php 如何使用php脚本下载视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4624012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to download the video using php script
提问by Meena
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.
“C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\Tom_20_amp__20Jerry_20race-1-5.flv”不是有效的 FLV 文件。
the video streaming properly. please guide me
视频流正确。请指导我
回答by Poelinca Dorin
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
回答by Olical
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');