由于我的电子书阅读器(Sony PRS-T1)的内置浏览器非常愚蠢,并且希望将.epub文件作为文本文件而不是下载它们,所以我试图迫使浏览器下载这个.htaccess文件的.epub文件:标题添加内容处理“附件”导致内部服务器错误
<FilesMatch "\.(?i:epub)$">
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
然而,这会导致内部服务器错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
当我离开了Header add Content-Disposition "attachment"
没有错误 - 但是,浏览器不会下载该文件:(
我做错了什么?内部服务器错误来自哪里?
[编辑2013-04-11]
我只是赢得了“人气问题,徽章”这个主题,这让我想起了加入一些信息。
我终于成功地迫使索尼PRS-T1的浏览器下载用下面的PHP功能
function startDownload($path, $mimeType) {
if(!file_exists($path)) {
// File doesn't exist, output error
exit('file not found');
} else {
$size = filesize($path);
$file = basename($path);
// Set headers
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-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Type: $mimeType");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
// Read the file from disk
readfile($path);
}
exit();
}
希望帮助别人一天。
你的日志说......? – 2012-04-08 23:37:32
对不起,不是我的服务器 - 也许我可以要求日志,但不知道。 – speendo 2012-04-09 00:15:15
[将Content-Disposition标题设置为仅在某个目录中的文件上附件?](http://support.microsoft.com/kb/3977159/set-content-disposition-header-to-attachment-only-on-文件在一定的导演) – 2015-04-24 02:22:49