sabatier Posted August 21, 2007 Share Posted August 21, 2007 Hi this is the script I'm using to download a file with a *.crl suffix: <?php $filename = $_GET['file']; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); if( $filename == "" ) { echo "<html><body>ERROR: download file NOT SPECIFIED. USE download.php?file=filepath</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo "<html><body>ERROR: File not found. USE download.php?file=filepath</body></html>"; exit; }; switch( $file_extension ) { case "crl": $ctype="application/pkcs-crl"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $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"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> This is how I link to it from my page: <a href='http://localhost:8080/xyz/download.php?file=filename etc etc.. When I click on the link I get the download prompt which shows the proper file size, but it downloads an empty file. The file is definitely there and is not empty... Anyone know what the problem is? Regards, Ruth Quote Link to comment https://forums.phpfreaks.com/topic/65945-force-download-problem/ Share on other sites More sharing options...
MadTechie Posted August 21, 2007 Share Posted August 21, 2007 nothing wrong with the script.. infact it looks like a mod of an force download old script i posted FTP in and check the file your attempting to download Quote Link to comment https://forums.phpfreaks.com/topic/65945-force-download-problem/#findComment-329674 Share on other sites More sharing options...
sabatier Posted August 21, 2007 Author Share Posted August 21, 2007 I've checked the file and there's absolutely nothing wrong with it. The funny thing about this script is that it works for some of the *.crl files but not for others... Quote Link to comment https://forums.phpfreaks.com/topic/65945-force-download-problem/#findComment-329679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.