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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 That could be a solution. Try it. Quote Link to comment 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) Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 22, 2009 Share Posted February 22, 2009 Good work Quote Link to comment 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.