Jump to content

Autodownload?


kla0005

Recommended Posts

Hi Guys,

 

Someone who know how to create a script that makes autodownload?

 

I want a php-file that i call download.php - When i insert a link with it il give it a id so i can update the number of 'how many who has downloadet the file'.

 

The SQL i can do by my self, byt what about the auto download?

The file link will be in $file ..

And the file can be a .rar, .zip, .msi, .exe - Thanks guys :)

Link to comment
Share on other sites

You will have to set the headers and use readfile. The header type you are looking for would I believe by Content-Disposition: attachment;    which should give you a starting point. If not I am sure Google has a ton of tutorials on this.

 

The google turtorials is stupid.

They only works with 1 type of file, and i dont know the 'header' function at all, so could u help me a bit more, please?

Link to comment
Share on other sites

funny. i just wrote/copied a file for this.

 

$file = "relative path to file";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="haha_download_my_spam.zip"');
    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);
    ob_clean();
    flush();
    
    header('Location: redirect');

} else { echo "FILE DNE"; }

 

only tested with a zip so far.

Link to comment
Share on other sites

funny. i just wrote/copied a file for this.

 

$file = "relative path to file";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="haha_download_my_spam.zip"');
    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);
    ob_clean();
    flush();
    
    header('Location: redirect');

} else { echo "FILE DNE"; }

 

only tested with a zip so far.

 

Yeah, it works..

But i had to chance your header with the download_my_spam.zip file thing, with:

header('Content-Disposition: attachment; filename="'.$file.'"');

Well, one more thing - How can i set a name to the file, so i can say that default download name the file has is: 'Cake'?

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.