ScopeXL Posted July 19, 2010 Share Posted July 19, 2010 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 More sharing options...
Wolphie Posted July 19, 2010 Share Posted July 19, 2010 .zip is a binary file, you need to open the file in binary mode. This just involves adding a 'b' to the second parameter of fopen. I.e. fopen('path/to/somefile.zip', 'rb') (read only, binary). Link to comment https://forums.phpfreaks.com/topic/208150-download-a-file-with-fopen-problem/#findComment-1088049 Share on other sites More sharing options...
ScopeXL Posted July 19, 2010 Author Share Posted July 19, 2010 The file is still corrupted when downloaded. Says its an unknown format or damaged. Link to comment https://forums.phpfreaks.com/topic/208150-download-a-file-with-fopen-problem/#findComment-1088331 Share on other sites More sharing options...
ScopeXL Posted July 21, 2010 Author Share Posted July 21, 2010 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. Link to comment https://forums.phpfreaks.com/topic/208150-download-a-file-with-fopen-problem/#findComment-1089291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.