1

我正在使用 php 集成强制下载。当我下载 flv 文件并在视频播放器中打开时,它显示错误。

$Filename = '/* file name */'; 
    header('Content-Description: File Transfer');
    header("Content-type: video/flv");
    header("Cache-Control: no-cache");
    header("Content-Transfer-Encoding: binary");
    header('Content-Disposition: attachment; filename=test.flv' );
    header("Pragma: no-cache");
    header('Content-length: '.filesize($Filename));
    $hFPi = fopen ("$Filename", "rb");
    while (!feof($hFPi))
    {
        $sBuf = fread ($hFPi, filesize($Filename) );
        echo $sBuf;
    } 
    fclose ($hFPi);

请帮忙..

4

4 回答 4

2
$Filename = '/* file name */'; 
$path = "../../upload/";
$file = $path.$filename;
savedata1();
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/flv");
header("Content-Transfer-Encoding: binary");
readfile($file);

这会帮助你。在你的代码中尝试一下,你会找到你的答案......

于 2012-10-11T07:04:43.723 回答
2

这段代码非常适合从我这里下载 mp4、flv、mpeg 文件。这里:$file_name = 下载的视频文件名,$file_path = 服务器中原始文件的基本路径。

header('Pragma: public'); // required   
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Type: video/mpeg");
header("Content-Transfer-Encoding: binary");

header('Cache-Control: must-revalidate, post-check=0, pre-check=0', false);
header('Cache-Control: private', false); // required for certain browsers  

ob_clean();
flush();
readfile($file_path);
exit;
于 2012-11-29T05:31:22.497 回答
0

尝试

           $Filename = 'test.flv'; 
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-type: video/flv");

            header("Content-Disposition: attachment; filename=".basename($filename).";" );
            header("Content-Transfer-Encoding: binary");
            readfile("$Filename "); 
于 2012-10-11T06:23:55.200 回答
0

这就是我强制下载文件的方法(对我来说它是 ZIP,但它应该适用于任何文件类型)。请记住,您必须对其进行调整,因为我存储数据库信息的方式与您可能做的不同。

header("Content Description: File Transfer");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must revalidate");
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename(".".$filepath)."");
header("Content-Length: " . filesize(".".$filepath));
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
readfile(".".$filepath);
于 2012-10-11T06:44:13.153 回答