danhodge Posted January 14, 2011 Report Share Posted January 14, 2011 I have probably brung this up before, but it is slightly driving me crazy... This is my current download PHP, which is working fine - i think someone here gave it me, or i C+P'd... But the point is, whenever i change the type to ZIP and the file to being a ZIP file, it wont work - it downloads, but it tells me i can't open the actual file itself... <?php $filename = "download.txt"; header("Content-Length: " . filesize($filename)); header('Content-Type: text/octet-stream'); header('Content-Disposition: attachment; filename=download.txt'); readfile($filename); ?> Anyone know why? Thanks, Danny Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 14, 2011 Report Share Posted January 14, 2011 Are you using the read Content-Type? I believe it should be "header("Content-type: application/zip");" This may also have some useful information: http://php.net/manual/en/function.readfile.php Quote Link to comment Share on other sites More sharing options...
danhodge Posted January 15, 2011 Author Report Share Posted January 15, 2011 This is the link to the website it is on The download is currently just one file in a ZIP, so that i can test it. Im thinking the security on my computer could explain why it isn't working - don't suppose you wanna try it and find out if it works on yours? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 15, 2011 Report Share Posted January 15, 2011 Nope, doesn't work for me either. Did you see my comments above? Quote Link to comment Share on other sites More sharing options...
danhodge Posted January 15, 2011 Author Report Share Posted January 15, 2011 i changed it to application/ZIP I was checking to see if that would work first - il check the link now.. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 15, 2011 Report Share Posted January 15, 2011 I just tried some sample code from PHP.net (http://php.net/manual/en/function.readfile.php) that I tweaked to work with .zip files, and it's working properly: http://www.falkendev.com/test.php (should download a "test.zip" file that contains a "test.txt" text file.) Here's my code: <?php $file = 'test.zip'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename='.basename($file)); 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($file)); ob_clean(); flush(); readfile($file); exit; } ?> Quote Link to comment Share on other sites More sharing options...
danhodge Posted January 15, 2011 Author Report Share Posted January 15, 2011 (edited) It works! For some reason when i tried that it wouldn't work for me... i must of been doing something wrong... Thank you so much Edited January 15, 2011 by danhodge 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.
Note: Your post will require moderator approval before it will be visible.