Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to download the video using php script

Tags:

php

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

like image 807
Meena Avatar asked Jan 20 '23 19:01

Meena


1 Answers

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
like image 161
Poelinca Dorin Avatar answered Jan 30 '23 01:01

Poelinca Dorin