UBB.Dev
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);
?>
My experience with downloading files is mostly in Perl, and I haven't dealt with downloading those file types, but here are a couple of things to look at:

Is your server Windows or Unix?

Does the problem vary depending on the clients platform (O/S, browser, etc.)?
Unix. Redhat 7.2.


The problem so far, has been consistent across client platform

Thanks,

HB
You might want to take a look at the user comments in the php manual.
It helped my a lot some while ago.

http://www.php.net/manual/en/function.header.php

If you can't get it working, i'll can provide some code, i come up with some time ago. Unfortunately, i don't have access to it until the weekend.

© UBB.Developers