Lazyness Posted February 3, 2011 Share Posted February 3, 2011 I've got an autodownloader for a file that I want my users to download when they click a link and the file is right but when a user downloads the file, the file is corrupted. <?php header('Content-Type: application/x-rar'); header('Content-Length: ' . strlen($data)); header('Content-Disposition: attachment; filename=Addypk.rar'); header('Content-type: application/octet-stream'); ?> It's not downloading the actual content of the file, rather, it's downloading the shell. Any ideas? Quote Link to comment Share on other sites More sharing options...
btherl Posted February 3, 2011 Share Posted February 3, 2011 All that script does is set headers. Where is the code to send the file? And what do you mean by "it's downloading the shell"? Quote Link to comment Share on other sites More sharing options...
Lazyness Posted February 3, 2011 Author Share Posted February 3, 2011 All that script does is set headers. Where is the code to send the file? And what do you mean by "it's downloading the shell"? So when you go to addypk.com/download/cache.php (remove if this is advertising), it will download the addypk.rar file automatically but nothing will be in the file. It's not actually sending anything but the shell of the .rar. Any ideas on what to do? Quote Link to comment Share on other sites More sharing options...
Lazyness Posted February 3, 2011 Author Share Posted February 3, 2011 <?php $data = file_get_contents('Addypk.rar'); header('Content-Type: application/x-rar'); header('Content-Length: ' . strlen($data)); header('Content-Disposition: attachment; filename=Addypk.rar'); header('Content-type: application/octet-stream'); die($data); ?> Fatal error: Allowed memory size of 18874368 bytes exhausted (tried to allocate 59728655 bytes) in /hermes/bosweb/web072/b723/ipg.addypkcom/download/cache.php on line 2 Quote Link to comment Share on other sites More sharing options...
Lazyness Posted February 3, 2011 Author Share Posted February 3, 2011 Bump. I'm really sorry for pestering you guys but I really, REALLY need this. If someone could post even a template to a downloader... I'd be more than happy. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 3, 2011 Share Posted February 3, 2011 I don't think you need to load the file into memory, which is what file_get_contents() does, and which is probably causing the memory error. you can pass the file through using readfile() something like this: <?php $data = "/full/path/to/Addypk.rar"; header('Content-Type: application/x-rar'); header('Content-Length: ' . filesize($data)); header('Content-Disposition: attachment; filename=Addypk.rar'); header('Content-type: application/octet-stream'); readfile($data); ?> 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.