// FILE DOWNLOADER // frenki - info@gbut.com // // usage: // ------ // just put a filename (with relative path to this script - optional) to download it // it will produce download a dialog with correct filename // // examples: // --------- // dl.php?some_file.mp3 - saves "some_file.mp3" from the same directory // dl.php?../other.zip - saves "other.zip" from the parent directory // dl.php?mp3/new/cool.mp3 - saves "cool.mp3" from the "mp3/new" directory // if it is a file if (is_file($_SERVER['QUERY_STRING'])){ $exp=explode(".",$_SERVER['QUERY_STRING']); if (in_array(strtolower($exp[count($exp)-1]),array('jpg','gif','png','pdf'))){ // check size of the file $size = filesize ($_SERVER['QUERY_STRING']); // headers header('Content-Type: application/octet-stream'); header('Accept-Ranges: bytes'); header('Content-Length: '.$size.'bytes'); header('Content-Disposition: attachment; filename='.basename($_SERVER['QUERY_STRING'])); header('Content-Description: File Transfer'); // read and output the file @readfile($_SERVER['QUERY_STRING']); } else exit; // if not - send error } else { echo '