gpt4 book ai didi

php - 强制 Sony PRS-T1 浏览器下载 .epub 文件

转载 作者:可可西里 更新时间:2023-11-01 16:34:42 24 4
gpt4 key购买 nike

我的电子书阅读器 (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 发现的结果:

http://tinypic.com/r/vzzkzp/5 readbeam

http://tinypic.com/r/2h7pbth/5 mine

最佳答案

您的 Content-Type header 与 readbeam 中的 header 不匹配。

application/epub 压缩包 != application/epub+zip

+ 可能被 PHP 视为一个空格,因为它似乎是通过 $_GET 传递的。

关于php - 强制 Sony PRS-T1 浏览器下载 .epub 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com