问题描述
||
这是我的代码。
<?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;
}
}
?>
解决方法
尝试使用此注释中的功能来强制浏览器打开下载文件对话框。它必须有所帮助。