下载的FLV文件无效

时间:2011-04-13 05:40:39

标签: zend-framework

这是我的代码..

<?php
ob_clean();
$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
// block any attempt to the filesystem
if (isset($params['file']) && basename($params['file']) == $params['file']) {

    $filename = $params['file'];

} else {

    $filename = NULL;

}

// define error message
$err = '<div class="right-panel fl">
                    <h1> Download Question </h1> <a href="JavaScript:void(0)" class="button" onclick="javascript:history.go(-1)" > Back </a>
                    <div class="gradient-box" style="margin-top:20px;" ><p style="color:#990000">Sorry, the file you are requesting is unavailable.</p></div></div>';

if (!$filename) {

    // if variable $filename is NULL or false display the message
    echo $err;

} else {

    // define the path to your download folder plus assign the file name
    $path = BASE_PATH.QUESTIONS_FILE_PUBLIC.$filename;
    $path2 = REL_PATH.QUESTIONS_FILE.$filename;

    // check that file exists and is readable
    if (file_exists($path) && is_readable($path)) {

        // get the file size and send the http headers
        $size = filesize($path);
        header("Content-type: video/flv");
        header('Content-Length: '.$size);
        header('Content-Disposition: attachment; filename='.$filename);
        header('Content-Transfer-Encoding: binary');

        // open the file in binary read-only mode
        // display the error messages if the file can´t be opened
        echo file_get_contents($path);
        //@readfile($path);
        exit;
        $file = @ fopen($path, 'rb');

        if ($file) {

            // stream the file and exit the script when complete
            fpassthru($file);
            exit;

        } else {

            echo $err;

        }

    } else {

        echo $err;

    }

}
?>

1 个答案:

答案 0 :(得分:0)

尝试使用this comment中的功能强制浏览器打开下载文件对话框。它必须有所帮助。

相关问题