头添加内容处置"附件"导致内部服务器错误 [英] Header add Content-Disposition "attachment" causes Internal Server error
问题描述
由于我的电子书阅读器的内置浏览器(索尼PRS-T1)是非常愚蠢的,想打开下载他们的.epub文件为文本文件,而不是,我试图迫使浏览器下载的.epub文件这个.htaccess文件:
< FilesMatch\。(我:EPUB)$>
ForceType指令的应用程序/八位字节流
头添加内容处置附件
< / FilesMatch>
不过,这会导致内部服务器错误:
内部服务器错误
服务器遇到一个内部错误或配置错误, 无法完成您的请求。
请与服务器管理员联系,站长@ localhost,且 通知他们错误发生的时间,以及任何你可能 这样做可能造成的错误。
这个错误的详细信息,可在服务器错误可用 登录。
当我离开了头添加内容处置附件
没有错误的 - 但是,浏览器不会下载该文件:(
我是不是做错了什么?哪里来的内部服务器错误的?
我刚刚获得了流行的问题,徽章这一主题,它提醒加入一些信息我。
我终于成功地强制下载索尼的PRS-T1浏览器,下面的PHP函数
函数startDownload($路径,$ MIMETYPE){
如果(!file_exists($路径)){
//文件不存在,输出错误
退出(找不到文件);
} 其他 {
$大小=档案大小($路径);
$文件=基本名($路径);
//设置头
标题(杂注:公); // 需要
标题(截止日期:0);
标题(缓存控制:必重新验证,后检查= 0,pre-检查= 0);
标题(缓存控制:私人,假); //需要某些浏览
标题(内容描述:文件传输);
标题(内容处置:附件;文件名= \$文件\);
标题(内容类型:$ MIMETYPE);
标题(内容传输编码:二进制);
标题(内容长度:$大小);
//从磁盘中读取文件
ReadFile的($路径);
}
出口();
}
希望有所帮助别人一天。
这可能是答案:
该模块头默认情况下未在Apache启用。所以,我们要 手动启用它。
要启用这个模块,以root身份登录,并创建符号链接 MODS的可用/ headers.load到MODS功能。在此之后,重载阿帕奇 而它的完成。要做到这一点,我用这个命令。
苏 - CD 在/ etc / apache2的/ MODS启用/ LN -s ../mods-available/headers.load headers.load SH /etc/init.d/apache2力重装
As the builtin browser of my ebook-reader (Sony PRS-T1) is quite stupid and wants to open .epub files as text-files instead of downloading them, I tried to force the browser to download the .epub files with this .htaccess file:
<FilesMatch "\.(?i:epub)$">
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
However, this causes an internal server error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@localhost 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.
When I leave out Header add Content-Disposition "attachment"
there is no error - however, the browser wouldn't download the file :(
Am I doing something wrong? Where does the Internal Server error come from?
[EDIT 2013-04-11]
I just earned the "popular question-badge" for this thread, which reminded me of adding some information.
I finally managed to force a download on Sony's PRS-T1 browser with the following php-function
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();
}
Hope that helps somebody one day.
This might be the answer:
The module headers is not enabled by default on Apache. So, we have to enable it manually.
To enable this module, log in as root, and create a symbolic link from mods-available/headers.load to mods-enabled. After that, reload apache and it's done. To do so, I've used this commands.
su - cd /etc/apache2/mods-enabled/ ln -s ../mods-available/headers.load headers.load sh /etc/init.d/apache2 force-reload
这篇关于头添加内容处置&QUOT;附件&QUOT;导致内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!