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

Link to comment
Share on other sites

<?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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.