Force Download Any file using PHP
Hello all, i need a working and error free script to force file downloads using PHP. plz help
I'm using a script from webinfopedia, its demo works fine but for my website is_readable($file) always returns FALSE but everything looks fine. if i skip this check, the file is downloaded but of 0 Bytes...
2 Answers
Thanks a ton for ur quick reply.. i'm going to use it now...
Posted: hassan.qazi 1 of 1 people found this answer helpful. Did you? Yes No <?php $filename = $_GET['filename']; $download_path = ""; if(eregi("\.\.", $filename)) die("I'm sorry, you may not download that file."); $file = str_replace("..", "", $filename); if(eregi("\.ht.+", $filename)) die("I'm sorry, you may not download that file."); $file = "$download_path$file"; if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist."); $type = filetype($file); $today = date("F j, Y, g:i a"); $time = time(); // Send file headers header("Content-type: $type"); header("Content-Disposition: attachment;filename=$filename"); header("Content-Transfer-Encoding: binary"); header('Pragma: no-cache'); header('Expires: 0'); // Send the file contents. set_time_limit(0); readfile($file); ?>and please give the folder 0777 chmode Posted: MacOS 3 of 3 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved