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? Link to comment https://forums.phpfreaks.com/topic/226527-autodownloader-failing/ 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"? Link to comment https://forums.phpfreaks.com/topic/226527-autodownloader-failing/#findComment-1169233 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? Link to comment https://forums.phpfreaks.com/topic/226527-autodownloader-failing/#findComment-1169249 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 Link to comment https://forums.phpfreaks.com/topic/226527-autodownloader-failing/#findComment-1169265 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. Link to comment https://forums.phpfreaks.com/topic/226527-autodownloader-failing/#findComment-1169438 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); ?> Link to comment https://forums.phpfreaks.com/topic/226527-autodownloader-failing/#findComment-1169444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.