由于我的电子书阅读器(Sony PRS-T1)的内置浏览器非常愚蠢,并且想要将 .epub 文件作为文本文件打开而不是下载它们,因此我尝试使用此 .htaccess 强制浏览器下载 .epub 文件文件:
<FilesMatch "\.(?i:epub)$">
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>
但是,这会导致内部服务器错误:
内部服务器错误
服务器遇到内部错误或配置错误,
无法完成您的请求。
请联系服务器管理员,webmaster@localhost 和
告知他们错误发生的时间以及您可能会发生的任何事情
所做的事情可能导致了错误。
有关此错误的更多信息可以在服务器错误中找到
日志。
当我离开时Header add Content-Disposition "attachment"
没有错误 - 但是,浏览器不会下载该文件:(
难道我做错了什么?内部服务器错误从何而来?
[编辑2013-04-11]
我刚刚获得了该主题的“热门问题徽章”,这提醒我添加一些信息。
我终于设法使用以下 php 函数在索尼的 PRS-T1 浏览器上强制下载
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();
}
希望有一天能对某人有所帮助。
这可能就是答案:
http://diogomelo.net/node/24 http://diogomelo.net/node/24
Apache 上默认不启用模块头。所以,我们必须
手动启用它。
要启用此模块,请以 root 身份登录,然后创建一个符号链接
mods-available/headers.load 至 mods-enabled。之后,重新加载apache
一切都完成了。为此,我使用了此命令。
su - cd
/etc/apache2/mods-enabled/ ln -s ../mods-available/headers.load
headers.load sh /etc/init.d/apache2 force-reload
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)