问题描述
由于我的电子书阅读器的内置浏览器(索尼PRS-T1)是非常愚蠢的,想打开下载他们的.epub文件为文本文件,而不是,我试图迫使浏览器下载的.epub文件这个.htaccess文件:
< FilesMatch\。(我:EPUB)$>
ForceType指令的应用程序/八位字节流
头添加内容处置附件
< / FilesMatch>
不过,这会导致内部服务器错误:
当我离开了头添加内容处置附件
没有错误的 - 但是,浏览器不会下载该文件:(
我是不是做错了什么?哪里来的内部服务器错误的?
我刚刚获得了流行的问题,徽章这一主题,它提醒加入一些信息我。
我终于成功地强制下载索尼的PRS-T1浏览器,下面的PHP函数
函数startDownload($路径,$ MIMETYPE){
如果(!file_exists($路径)){
//文件不存在,输出错误
退出(找不到文件);
} 其他 {
$大小=档案大小($路径);
$文件=基本名($路径);
//设置头
标题(杂注:公); // 需要
标题(截止日期:0);
标题(缓存控制:必重新验证,后检查= 0,pre-检查= 0);
标题(缓存控制:私人,假); //需要某些浏览
标题(内容描述:文件传输);
标题(内容处置:附件;文件名= \$文件\);
标题(内容类型:$ MIMETYPE);
标题(内容传输编码:二进制);
标题(内容长度:$大小);
//从磁盘中读取文件
ReadFile的($路径);
}
出口();
}
希望有所帮助别人一天。
这可能是答案:
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:
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:
这篇关于头添加内容处置&QUOT;附件&QUOT;导致内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!