English 中文(简体)
如何用这些 HTTP 信头为此文件服务?
原标题:How to serve this file with these HTTP headers?
  • 时间:2012-05-24 13:18:28
  •  标签:
  • php

I am using a shared hosting, so I can t edit Apache settings. I need to allow users to download a .crx file in this way:

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或其他方式?

最佳回答
<?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)
?>
问题回答

使用 < a href=>" "http://php.net/manual/en/form.header.php" rel="nofollow"\\\ code>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

尝试添加此行 :

AddType application/x-chrome-extension crx

您的. httaccess 文件 。

根据我的评论:

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

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

然后,如果文件存在于您的服务器上,请使用 readfile 方法发送文件,或者如果文件是在执行过程中生成的,请重复文件内容。

这个工作很好

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




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签