Click to See Complete Forum and Search --> : Download with link


Luke101
09-30-2006, 02:08 PM
Is there a way i can download a video right away without having the guest to right click? Can anyone help me?

pcthug
09-30-2006, 08:42 PM
Save the following code as download.php, save it in the directory where all your videos are located. To access a file use the following format:

http://www.yourdomain.com/path/to/video/dir/download.php?file=video_filename.mpg

<?php

$filename = dirname(__FILE__) . '/' . $_GET['file'];

// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

$pathinfo = pathinfo($filename);

if($filename == dirname(__FILE__) . '/') {
exit('No filename specified.');
}

elseif(!file_exists($filename) || strpos($filename, '../') {
exit('No such file exisits');
};

switch( $file_extension ) {
case 'avi': $ctype = 'video/x-msvideo'; break;
case 'mov': $ctype = 'video/quicktime'; break;
case 'mpeg':
case 'mpg': $ctype= 'video/mpeg'; break;
case 'ra': $ctype = 'video/x-pn-realaudio'; break;
case 'ram' : $ctype = 'video/x-pn-realaudio'; break;
case 'wmv': $ctype= 'video/windowsmedia';
default: $ctype="video/force-download";
}

header("Pragma: public");
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");
header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filename));
readfile($filename);
exit();

?>

Luke101
10-03-2006, 08:13 PM
thanks