I’m trying to create a download links for my file so the download will be forced , this is my costume page I have assigned it to a download page, but the problem is that it downloads an empty file, and the issue is not in PDF format I tried images as well it always has 0 bytes files , the path is correct Ive checked already , I suspect that it has something to do with WordPress native headers conflicting , the code seems to be correct I used it in my other non-WordPress sites , here is the code:
<?php /* Template Name: download-main-ebook */ ?> <?php $file = get_stylesheet_directory_uri(). "/homepage/ebook.pdf"; header('Pragma: public'); // required header('Expires: 0'); // no cache header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private',false); header('Content-Type: '.'html'); header('Content-Disposition: attachment; filename=ebook.pdf'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.filesize($file)); // provide file size header('Connection: close'); readfile($file); // push it out exit(); ?>
please help !