Jump to content

Download a File with fopen Problem


ScopeXL

Recommended Posts

Hello,

 

I seem to be having a problem with my script. I can't seem to get it to download a file using fopen. readfile works great, but with files that exceed 4MB size readfile will not work. So to fix this I use fopen for files over 4MB. When it tries to download the file, I get an error saying that the source file cannot be read. I double checked the file its attempting to download and it has permissions 0644, and when transferred via FTP it works fine. Can anyone shed some light on why this is broken? (This just recently started happening, for a while the script worked great).

 

$filename = 'downloads/file.zip';
if (filesize($filename) > 4194304)
{
$fp = fopen($filename, 'r');
	while (!feof($fp))
	{
		echo fread($fp, 8192);
		flush();
	}
fclose($fp);
}
else
{
readfile($filename);
}

 

Any help is appreciated. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/208150-download-a-file-with-fopen-problem/
Share on other sites

bump. Still having problems with this. I've checked the permissions on the downloads/ folder and they are 0777 (so new files can be uploaded) and each uploaded file is 0644, not sure if that is 100% correct, but the system isn't downloading the files. It's downloading blank, corrupted archives.

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.