强制下载FLV文件无法在PHP中运行

时间:2012-10-11 06:19:51

标签: php download

使用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 个答案:

答案 0 :(得分: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);
这将有助于你。在你的代码中尝试一下,你会找到答案......

答案 1 :(得分: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;

答案 2 :(得分: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 "); 

答案 3 :(得分: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);