PHP for authorized Download of Video files... - 04/09/2003 1:37 AM
I use the following file get.php - to let users download some video files ONLY through the get.php file. The video files (WMV, MPG, RAM, RM) are stored in an 'outside' webroot directory and are called by get.php.
The problems however -
(a) Every file downloaded is named get.<extension>
(b) The RM or real media files are corrupt after open/ download through this script. It downloads the perfect size for Real Media, but then it fails to open
MPEG files run fine though. Any help greatly appreciated.
The PHP code for get.php--
<?
define('FILEDIR', '/home/myhotboard.com/downloads/');
//storage directory outside the root
$path = FILEDIR . $file;
$mimetype = array(
'doc'=>'application/msword',
'htm'=>'text/html',
'html'=>'text/html',
'jpg'=>'image/jpeg',
'pdf'=>'application/pdf',
'txt'=>'text/plain',
'xls'=>'application/vnd.ms-excel'
);
$p = explode('.', $file);
$pc = count($p);
//send headers
if(($pc > 1) AND isset($mimetype[$p[$pc - 1]]))
{
//display file inside browser
header("Content-type: " . $mimetype[$p[$pc - 1]] . "\n");
}
else
{
//force download dialog
header("Content-type: application/octet-stream\n");
header("Content-disposition: attachment; filename="$file"\n");
}
header("Content-transfer-encoding: binary\n");
header("Content-length: " . filesize($path) . "\n");
//send file contents
$fp=fopen($path, "r");
fpassthru($fp);
?>
The problems however -
(a) Every file downloaded is named get.<extension>
(b) The RM or real media files are corrupt after open/ download through this script. It downloads the perfect size for Real Media, but then it fails to open
MPEG files run fine though. Any help greatly appreciated.
The PHP code for get.php--
<?
define('FILEDIR', '/home/myhotboard.com/downloads/');
//storage directory outside the root
$path = FILEDIR . $file;
$mimetype = array(
'doc'=>'application/msword',
'htm'=>'text/html',
'html'=>'text/html',
'jpg'=>'image/jpeg',
'pdf'=>'application/pdf',
'txt'=>'text/plain',
'xls'=>'application/vnd.ms-excel'
);
$p = explode('.', $file);
$pc = count($p);
//send headers
if(($pc > 1) AND isset($mimetype[$p[$pc - 1]]))
{
//display file inside browser
header("Content-type: " . $mimetype[$p[$pc - 1]] . "\n");
}
else
{
//force download dialog
header("Content-type: application/octet-stream\n");
header("Content-disposition: attachment; filename="$file"\n");
}
header("Content-transfer-encoding: binary\n");
header("Content-length: " . filesize($path) . "\n");
//send file contents
$fp=fopen($path, "r");
fpassthru($fp);
?>