我正在尝试查看 PDF。此代码曾经在 Firefox 中工作。现在,只要声明 header("Content-Type: $ctype"); 达到,文件被下载。执行之后没有 die() 语句。到底是怎么回事?我在 Firefox 20.0.1 上。在 IE10 中运行良好。
更新:已解决 - 见下文
if (file_exists($fullfilename)){
// Parse Info / Get Extension
$fsize = filesize($fullfilename);
$path_parts = pathinfo($fullfilename);
$ext = strtolower($path_parts["extension"]);
// Determine Content Type
switch ($ext) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
// video
case "3gp": $ctype='video/3gpp'; break;
case "3g2": $ctype='video/3g2'; break;
case "avi": $ctype='video/avi'; break;
case "mp4": $ctype='video/mp4'; break;
case "ogv": $ctype='video/ogg'; break;
case "mov": $ctype='video/quicktime'; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
if ($mode == "view"){
// View file
header('Content-Disposition: inline; filename='.basename($fullfilename));
}
else {
// Download file
header('Content-Disposition: attachment; filename='.basename($fullfilename));
}
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
if (ob_get_length() > 0 ) {
//ob_end_clean();
ob_clean();
flush();
}
readfile( $fullfilename );
}
else {
die('File Not Found: ' . $fullfilename);
}