我的电子书阅读器(Sony PRS-T1)的内置浏览器不知为何不喜欢下载 .epub 文件。
通常它会像打开文本文件一样打开 .epub 文件。
通过这个 php-download-script,我设法强制浏览器下载我存储在服务器上的文件:
<?php
$path = $_GET['path'];
$mimeType = $_GET['mimeType'];
if(!file_exists($path)) {
// File doesn't exist, output error
die('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();
?>
现在,PRS-T1 会下载该文件,但由于某种原因,我不明白它将文件扩展名从 .epub 更改为 .htm - 这很奇怪。
但似乎有一种方法可以做到这一点:当我从 readbeam.com 下载 .epub 文件时它的工作原理就像预期的那样(我在 http://www.mobileread.com/forums/showthread.php?t=163466 找到了这个提示)。
是什么让他们的配置和我的配置之间存在差异?
这是我使用 firebug 发现的内容:
最佳答案
您的 Content-Type
header 与 readbeam 中的 header 不匹配。
application/epub zip
!= application/epub+zip
+
可能被 PHP 视为空格,因为您似乎是通过 $_GET 传递它。
关于php - 强制 Sony PRS-T1 的浏览器下载 .epub 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092898/