kla0005 Posted February 1, 2010 Share Posted February 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/ Share on other sites More sharing options...
premiso Posted February 1, 2010 Share Posted February 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005100 Share on other sites More sharing options...
kla0005 Posted February 1, 2010 Author Share Posted February 1, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005101 Share on other sites More sharing options...
schilly Posted February 1, 2010 Share Posted February 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005104 Share on other sites More sharing options...
kla0005 Posted February 1, 2010 Author Share Posted February 1, 2010 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'? Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005106 Share on other sites More sharing options...
schilly Posted February 1, 2010 Share Posted February 1, 2010 the part you just changed is where you set the file name. Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005113 Share on other sites More sharing options...
kla0005 Posted February 1, 2010 Author Share Posted February 1, 2010 the part you just changed is where you set the file name. oh.. Hahaha xD Quote Link to comment https://forums.phpfreaks.com/topic/190568-autodownload/#findComment-1005132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.