PDA

View Full Version : Header to show .avi video ?


V@no.
05-23-2003, 04:10 PM
Hi!
I made a script that I use as antileach, it reads files then sends back to the browser the data from the file.
it works just fine with images, but it doesnt with video/audio files...
I use this header set for .jpeg images:
header ("Content-type: image/jpeg");
echo $data;
*in $data variable it has data of image content

so, I've tryed use header ("Content-type: video/avi"); but it still shows the file as text...
can someone give me a hint how to do so?
thx.

Spookster
05-23-2003, 04:54 PM
Did you try?

video/x-msvideo

V@no.
05-24-2003, 12:23 AM
yes, I've tryed that before...
not sure what could be wrong...it MUST work that way! I know it....
I can send files to download window, but cant show them as they are...

Spookster
05-24-2003, 02:26 AM
Then most likely your server is not configured to serve that file type. If you are allowed to use .htaccess files then create one and put the following into it:



AddType video/x-msvideo avi
AddType video/avi avi

V@no.
05-24-2003, 02:38 AM
very strange, cause the files can be played through IE plugin media player (embeded) when used direct link for the .avi file
but when the file reads by .php script and sends to the browser, it can not play...

I've tryed both your hints, nothing changed...

Spookster
05-24-2003, 02:50 AM
Without seeing the script you are using then I don't what else to tell ya.

V@no.
05-24-2003, 02:56 AM
well...ok, here is modifyed script, just to show the basics:
$file = "C:/test.avi";
$file_size = filesize($file);
$fp = fopen($file, "rb");
$data = fread ($fp, $file_size);
fclose($fp);
header ("Content-type: video/avi");
echo $data;

l3vi
05-24-2003, 03:05 AM
Im just kinda guessing here, but from experience, (very little), I think that what your doing wrong is reading the file.... Cant u use something like readfile or something??

V@no.
05-24-2003, 03:27 AM
Originally posted by l3vi
Cant u use something like readfile or something??
readfile(); reads whole file, and if file big, it can cross the memory limit and get error.
I use fread(); because I have set read only 4kb of the file per cicle. (in the example I posted, I have simplifyed it ;) )
anyway, I just tryed readfile(); and got about the same...exept, my server processor loaded on 100% for about 10sec for 10mb file...

V@no.
05-26-2003, 05:30 AM
ok, I think I figured out why I'm having this problem...it's not because of header, its because for some reason when php reads files bigger then 500-700kb it through back to the browser corrupted output...
I have set in php.ini all "MAX..MEMORY..LIMITs" to 512mb but still same problem...timeouts set to 360sec...
but, what's interesting, when I add a header that make files being downloaded header("Content-Disposition: attachment; filename=\"".$filename."\"\n");
header("Content-Type: application/octet-stream\n"); it works just fine...so, I'm confused why its like that...

V@no.
06-12-2003, 12:26 PM
if anyone interesting, I just solved my problem...I forgot add before echo $data;:
header ("Content-Length: ".strlen($data)."\n\n");