6

我需要使用 PHP 在我的共享主机上托管我的 chrome 扩展。

我知道我的服务器必须使用适当的 HTTP 标头:code.google.com/chrome/extensions/hosting.html

但是,如何设置我的服务器将这些标头发送到 .crx 文件?

4

2 回答 2

7

如果您在共享主机上并且无法更改服务器配置,请使用 PHP:

<?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;
}
?>

资源

这将强制$file下载带有自定义标题的文件(由变量指定)。

于 2012-05-24T19:48:12.603 回答
1

我不知道您使用的是什么 Web 服务器,但对于 Apache,您可以执行以下操作:

  1. /path/to/your/httpd/conf/mime.types
  2. 添加这一行:application/x-chrome-extension crx在文件末尾
  3. 重新启动您的网络服务器:killall -HUP httpd

或者您可以尝试将此行添加到您的.htaccess文件中:

AddType application/x-chrome-extension crx

它应该工作!

于 2012-05-24T12:34:14.630 回答