Jump to content

Autodownloader Failing?


Lazyness

Recommended Posts

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

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?

<?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

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.