|
Posted by Lupus Yonderboy on 07/31/06 08:32
Having the need to make some videos available for download from my website,
some time ago I created a script by putting together some snippets from
different examples found on the net (the first one was from php.net function
reference), until everything appeared to run smoothly. The file types I
wanted to release through the download function are .avi, .wmv, .mov and
..mp4. For some time everything went peachy, until recently I uploaded
another video and I noticed that my script doesn't work with files above a
given filesize, say around 20 Mb: Firefox opens the small download window on
the bottom right and it closes right away, saving a 0 byte file; IE6 does
just the same, besides it names the file wrongly (with the name of the .php
file containing the call to the download script). Can anybody provide an
hint? The script follows:
<?php
function getfile($name, $file){
$len = filesize($file);
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
//This will set the Content-Type to the appropriate setting for the file
switch( $file_extension ) {
case "mov": $ctype="video/quicktime"; break;
case "avi": $ctype="video/x-msvideo"; break;
case "wmv": $ctype="video/x-msvideo"; break;
//The following are for extensions that shouldn't be downloaded
//(sensitive stuff, like php files)
case "php":
case "htm":
case "html":
case "txt": die("<b>Cannot be used for ". $file_extension ."
files!</b>"); break;
default: $ctype="application/force-download";
}
//Begin writing headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
//Force the download
$header="Content-Disposition: attachment; filename=\"$name\";";
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len);
@readfile($file);
exit;
}
?>
Thank you,
lupus
--
"I strongly recommend if you only ever read one book in your life...
you keep your fucking mouth shut." - (www.banksy.co.uk)
[Back to original message]
|