Jump to content

Forced Download files are 0 bytes


thindery1

Recommended Posts

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

  • 4 weeks later...

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.  ;D

-Jim

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.