2012-05-24 99 views

回答

6

如果你是一个共享的主机,并且不能更改服务器的配置,使用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; 
} 
?> 

source

这将迫使文件($file变量指定)下载与定制的头。

+0

谢谢@Konard,这非常有帮助。 – zur4ik

+2

从技术角度来看,这是正确的,但在新版Chrome浏览器中无法使用:https://support.google.com/chrome_webstore/answer/2664769 – bfncs

1

我不知道什么是您使用的网络服务器,但对于Apache的,你可以做到以下几点:

  1. /path/to/your/httpd/conf/mime.types
  2. 加入这一行:application/x-chrome-extension crx在文件
  3. 重启结束你的web服务器:killall -HUP httpd

或者你可以尝试加入这一行到您的.htaccess文件:

AddType application/x-chrome-extension crx 

它应该工作!

+0

我正在使用共享主机,所以我无法编辑Apache设置。我可以在PHP中执行此操作吗? – xRobot

+1

我找到了一些东西。您可以尝试将这些添加到您的.htaccess:AddType应用程序/ x-chrome-extension crx – divaka