treeleaf20 Posted July 10, 2012 Share Posted July 10, 2012 All, I've got the following code to force a file download for a zipfile that I just created: $zip_name = 'download.zip'; $result = create_zip($other_files_to_zip,$zip_name,true); if($result){ echo "The filesize is: ".filesize($zip_name); header('Content-Type: application/zip'); header('Content-disposition: attachment; filename=filename.zip'); header('Content-Length: ' . filesize($zip_name)); readfile($zip_name); } When I echo out the filesize it shows a correct size and it prompts me to download the filename.zip which is ok since it's just a filename but then when I save the document and try and open Windows says that Windows cannot open the folder because the folder is invalid. Any ideas on how to resolve an issue like this? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/265493-readfile-in-php-isnt-downloading-file/ Share on other sites More sharing options...
xyph Posted July 10, 2012 Share Posted July 10, 2012 You can't output a string if you are outputting the zip file's contents. It will get appended to the binary data of the zip file, potentially corrupting it. Your only output should be the contents of the zip file. Quote Link to comment https://forums.phpfreaks.com/topic/265493-readfile-in-php-isnt-downloading-file/#findComment-1360665 Share on other sites More sharing options...
treeleaf20 Posted July 10, 2012 Author Share Posted July 10, 2012 Even if I remove that from the code it still doesn't work. I just added that as more of a debugging tool to see if the file even had contents in it. Either way, it still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/265493-readfile-in-php-isnt-downloading-file/#findComment-1360668 Share on other sites More sharing options...
xyph Posted July 10, 2012 Share Posted July 10, 2012 You're gonna have to provide some stand-alone code we can use to replicate the issue then. Quote Link to comment https://forums.phpfreaks.com/topic/265493-readfile-in-php-isnt-downloading-file/#findComment-1360673 Share on other sites More sharing options...
samshel Posted July 10, 2012 Share Posted July 10, 2012 try putting an exit after readfile. Is there any space at the end of the file after ?> PHP close tags? Manually try downloading the file and see if it opens? Quote Link to comment https://forums.phpfreaks.com/topic/265493-readfile-in-php-isnt-downloading-file/#findComment-1360675 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.