Hendo Posted April 16, 2008 Share Posted April 16, 2008 Hi, I've been wanting to add a simple download script to my website, to allow members to download .MP4 videos, however I can't find a tutorial that allows me to do that. I searched for a tutorial, but couldn't find anything that just allowed users to download the file as usual. I'm fairly certain you can use PHP to do this, I just don't know where to start. Any help is appreciated, and if it isn't PHP that does downloads, could someone tell me the best way to go about it? Thank you Link to comment https://forums.phpfreaks.com/topic/101373-solved-simple-downloads/ Share on other sites More sharing options...
jonsjava Posted April 16, 2008 Share Posted April 16, 2008 a modified version of a script I found at http://elouai.com/force-download.php: <?php $filename = $_GET['file']; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); if( $filename == "" ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>"; exit; }; switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; case "mp4": $ctype="video/mp4"; break; default: $ctype="application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> Link to comment https://forums.phpfreaks.com/topic/101373-solved-simple-downloads/#findComment-518518 Share on other sites More sharing options...
Hendo Posted April 16, 2008 Author Share Posted April 16, 2008 Looks perfect, but I can't get it to work(N) I put in my file name, and the file was in the same folder as the script, but it kept saying: "ERROR: File not found. USE force-download.php?file=filepath" What does it mean by that? Link to comment https://forums.phpfreaks.com/topic/101373-solved-simple-downloads/#findComment-518548 Share on other sites More sharing options...
jonsjava Posted April 16, 2008 Share Posted April 16, 2008 it worked fine for me (example: http://vent.jonsjava.com/down.php?file=bottleopener.mp4 Link to comment https://forums.phpfreaks.com/topic/101373-solved-simple-downloads/#findComment-518571 Share on other sites More sharing options...
Hendo Posted April 16, 2008 Author Share Posted April 16, 2008 Sorted, thank you for your help! Link to comment https://forums.phpfreaks.com/topic/101373-solved-simple-downloads/#findComment-518629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.