loony383 Posted February 22, 2009 Share Posted February 22, 2009 Ok so im using the following header code to send files PHP Code: header('Content-Description: File Transfer'); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename='.basename($download_url)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($download_url)); ob_clean(); flush(); readfile($download_url); But whenever a user downloads a file it's corrupted? My website allows users to upload files. I checked the files on the server and they're fine, not corrupted but when the user downloads the file it's corrupted? Users can upload files with any extension to my website. Help anyone? Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/ Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Open downloaded file in text editor and check if anything was attached to the beginning. Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768563 Share on other sites More sharing options...
loony383 Posted February 22, 2009 Author Share Posted February 22, 2009 There was this: <br /> <b>Warning</b>: filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for http://domain.net/uploads/1235318572/header.png in <b>/home/username/public_html/files/include/cookie.php</b> on line <b>96</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/username/public_html/files/include/cookie.php:96) in <b>/home/username/public_html/files/include/cookie.php</b> on line <b>96</b><br /> ‰PNG Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768576 Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Here's your reason. filesize fails. Now you have to find out why. Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768578 Share on other sites More sharing options...
loony383 Posted February 22, 2009 Author Share Posted February 22, 2009 I have a filesize of bytes in the database for each file, shall i try replacing the filesize with the number? Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768581 Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 That could be a solution. Try it. Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768584 Share on other sites More sharing options...
loony383 Posted February 22, 2009 Author Share Posted February 22, 2009 That fixed the problem but now I have another. Any documents that have a space in them get corrupted because it doesn't find it. As soon as there is a space in the file name it cuts it off (resulting in it not finding the file and instead just downloads an file full of the error when opened notepad). Anyone know an easy solution to this? (i don't really want to edit the unloader to rename the files with underscores) Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768586 Share on other sites More sharing options...
loony383 Posted February 22, 2009 Author Share Posted February 22, 2009 I worked it out,. I tried to make it remove the spaces and replace them with underscores in the uploader and it was easier than expected.. Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768615 Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Good work Link to comment https://forums.phpfreaks.com/topic/146380-solved-header-download-dialog-corrupting-files/#findComment-768627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.