Meena
Meena

Reputation: 967

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

Upvotes: 4

Views: 26985

Answers (2)

Poelinca Dorin
Poelinca Dorin

Reputation: 9703

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

Upvotes: 9

Olical
Olical

Reputation: 41352

If you are looking to allow files to be downloaded instead of streamed then something like this should work. You will obviously need to change the paths.

// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="download.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');

EDIT

In your case it will be something like this.

// We'll be outputting a video
header('Content-type: video/flv');

// It will be called video.flv
header('Content-Disposition: attachment; filename="video.flv"');

// The PDF source is in original.flv
readfile('original.flv');

Upvotes: -1

Related Questions