Tuesday, June 25, 2013

Download any file with php using header

You can download any file using this
Step1:Copy the code to a page called download.php(note:dont need any html tags should only contains this code)
Step2:Create a link with your file name
<a href="download.php?filename=myfile.jpg">Download</a> in your page(not at download page)


<?php
 //BUILD THE FILE INFORMATION
     $file = $_REQUEST['filename'];

     //CREATE/OUTPUT THE HEADER
     header("Content-type: application/force-download");
     header("Content-Transfer-Encoding: Binary");
     header("Content-length: ".filesize($file));
     header("Content-disposition: attachment; filename=\"".basename($file)."\"");
     readfile($file);
?>

No comments:

Post a Comment