0

我使用的是共享主机,因此无法编辑 Apache 设置。我需要允许用户以这种方式下载 .crx 文件:

1) The file has the content type application/x-chrome-extension
2) The file is not served with the HTTP header X-Content-Type-Options: nosniff
3) The file is served with one of the following content types:
- empty string
- "text/plain"
- "application/octet-stream"
- "unknown/unknown"
- "application/unknown"

我怎样才能用 PHP 或其他方式做到这一点?

4

5 回答 5

1

使用header()功能。

header('Content-Type: text/plain');

更新:

抱歉,我忘记了文件是 .crx :)

如果您的文件是cool_app.crx,请编写一个包装器,例如cool_app.php

<?php
header('Content-Type: application/x-chrome-extension');
include 'cool_app.crx';

然后将您的链接指向cool_app.php.

于 2012-05-24T13:21:09.837 回答
1
<?php
header("Content-Type: application/x-chrome-extension; charset=UTF-8");   // use here both proper settings for your case
//  header("Content-Length: " .filesize($your_crx_file));    // this is realy optional, I do recomend to not include this sentence
header('Content-Disposition: attachment; filename="TheNameThatYouWant.crx"');    // this set the name of the downloaded file on browser side.
readfile($your_crx_file)
?>
于 2012-05-24T13:45:59.500 回答
1

尝试添加这一行:

AddType application/x-chrome-extension crx

到您的 .htaccess 文件。

于 2012-05-24T14:02:57.987 回答
0

根据我的评论:

header('content-type: text/plain'); // set the content-type
readfile('path-to-crx.crx');

您首先使用该header函数设置内容类型。

然后,如果文件存在于您的服务器上,请使用该readfile方法发送文件,或者如果它是在执行期间生成的,则只需回显文件内容。

于 2012-05-24T13:31:02.080 回答
0

这项工作很好

<?php
$file = 'extension.crx';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/x-chrome-extension');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>
于 2013-05-12T20:29:44.263 回答