dqys98341
dqys98341
2012-10-11 06:19

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

已采纳

am integrating force download using php. when i download the flv files and open in video players its shows error.

$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);

Please help..

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • duanboshe0001 duanboshe0001 9年前
    $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);
    

    this will help u. Try it in ur code and u will find ur answer...

    点赞 评论 复制链接分享
  • dousuie2222 dousuie2222 9年前

    This is what I do to force a download of a file (for me it's ZIP but it should work for any file type though). Keep in mind you'll have to tweak it as I store my db information differently than you probably do.

    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);
    
    点赞 评论 复制链接分享
  • doufei2194 doufei2194 9年前

    Try

               $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 "); 
    
    点赞 评论 复制链接分享
  • dongwen7187 dongwen7187 9年前

    This code working great to download mp4, flv, mpeg file from my end. Here: $file_name = The Downloaded video file name, $file_path = Base Path of the original file in the server.

    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;
    
    点赞 评论 复制链接分享

为你推荐