gpt4 book ai didi

apache - header 添加 Content-Disposition "attachment"导致内部服务器错误

转载 作者:行者123 更新时间:2023-12-01 12:55:16 25 4
gpt4 key购买 nike

由于我的电子书阅读器 (Sony PRS-T1) 的内置浏览器非常愚蠢,想要将 .epub 文件作为文本文件打开而不是下载它们,我试图强制浏览器下载 .epub 文件这个 .htaccess 文件:

<FilesMatch "\.(?i:epub)$">
ForceType application/octet-stream
Header add Content-Disposition "attachment"
</FilesMatch>

但是,这会导致内部服务器错误:

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.

当我省略 Header add Content-Disposition "attachment" 时,没有错误 - 但是,浏览器不会下载文件 :(

我做错了什么吗?内部服务器错误从何而来?

[编辑 2013-04-11]

我刚刚获得了这个话题的“热门问题徽章”,这让我想起了补充一些信息。

我终于设法使用以下 php 函数在 Sony 的 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

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

关于apache - header 添加 Content-Disposition "attachment"导致内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067276/

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