Meena Meena - 2 months ago 6
PHP Question

how to download the video using php script

In my program I want to add a download option to download the currently straming video. I tried this code:

$psp = "Tom_20_amp__20Jerry_20race-1.flv";
header("Content-type:application/octet-stream");
header("Content-Disposition:attachment;filename=$psp");


But I get this error:


"C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\Tom_20_amp__20Jerry_20race-1-5.flv" is not a valid FLV file.


the video streaming properly. please guide me

Answer

Change you're header from :

header("Content-type:application/octet-stream");

To :

header("Content-type: video/flv");

Then you can do :

header("Content-Disposition:attachment;filename=\"$psp\"");
//allways a good idea to let the browser know how much data to expect
header("Content-length: " . filesize($psp) . "\n\n"); 
echo file_get_contents($psp); //$psp should contain the full path to the video
Comments