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
https://forums.phpfreaks.com/topic/190568-autodownload/
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
https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005101
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
https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005104
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
https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005106
Share on other sites

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.