我正在尝试查看PDF。此代码曾用于Firefox。现在,只要声明标题(“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);
}
答案 0 :(得分:0)
我不知道Firefox应用程序PDF设置如何更改为"下载"而不是观看。现在修好了。