PHP allows you to change the HTTP headers of files, so that you can force a file to be downloaded that normally the browser would load in the same window. This is perfect for files like PDFs, document files, images, and video that you want your customers to download rather than read online. ( Jennifer Kyrnin )
Lets Start,
1. Upload file to the web server that you want to make available for download.
2. Create a New PHP file download.php
3. Open PHP file and copy paste following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $output = file_get_contents('your_file_here.extension'); if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } $ctype="application/force-download"; header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=\"Your_File_Here.Extension\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".strlen($output)); echo $output; exit(); ?> |
4. Link your php file as download link
<a href="download.php">Download</a>
Download