由於我的電子書閱讀器(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