thindery1 Posted March 26, 2009 Share Posted March 26, 2009 I have googled as much as I can about this topic. I have looked and implemented many different suggestions, but the file that pops up to download is always 0 bytes! What I am using: $filename = basename($thefile); $file_extension = strtolower(substr(strrchr($filename,"."),1)); // required for IE if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } //This will set the Content-Type to the appropriate setting for the file switch( $file_extension ) { case "mp3": $ctype="audio/mpeg"; break; case "m4r": $ctype="audio/Ringtone"; break; //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files) case "php": case "htm": case "htaccess": case "sql": case "html": case "txt": die("<b>Cannot be used for ". $file_extension ." files!</b>"); break; default: $ctype="application/octet-stream"; } // Set headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=". $filename); header("Content-Length: ".filesize($thefile)); header("Content-Type: ". $ctype); header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); ob_clean(); flush(); // Read the file from disk readfile($thefile); // End force download exit; Anybody have any ideas? The files are .m4r - iPhone ringtones. See it in action at www.mipages.net/ringtones/ Link to comment https://forums.phpfreaks.com/topic/151196-forced-download-files-are-0-bytes/ Share on other sites More sharing options...
thindery1 Posted March 27, 2009 Author Share Posted March 27, 2009 anybody? Link to comment https://forums.phpfreaks.com/topic/151196-forced-download-files-are-0-bytes/#findComment-794916 Share on other sites More sharing options...
corbin Posted March 27, 2009 Share Posted March 27, 2009 Try seeing what filesize($thefile) is saying. Link to comment https://forums.phpfreaks.com/topic/151196-forced-download-files-are-0-bytes/#findComment-794919 Share on other sites More sharing options...
russej20 Posted April 24, 2009 Share Posted April 24, 2009 I was doing something similar with the readfile() function last night and was downloading 0 byte files. It turned out that I didn't have the actual file where readfile was looking so it always downloaded a 0 byte file. Once I took care of that, it seemed to be better. YMMV. I am not a Programmer. Just a code "hacker" wannabe. -Jim Link to comment https://forums.phpfreaks.com/topic/151196-forced-download-files-are-0-bytes/#findComment-818284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.