PHP强制下载.app文件?

时间:2013-07-25 19:02:00

标签: php

我正在尝试强制下载.app文件..

试过以下但是它只给了我一个空的.app文件:

<?php
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=Application.app");
    header("Content-Type: application/zip");
    header("Content-Transfer-Encoding: binary");

?>

3 个答案:

答案 0 :(得分:1)

替换

header("Content-Type: application/zip");

header("Content-Type: application/octet-stream");

然后使用readfile()输出您的文件。而且我还建议摆脱?>标签。所以它应该是:

<?php
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=Application.app");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");

readfile('Application.app');     // replace Application.app with right filename or full path to subject file

答案 1 :(得分:0)

在最后添加此行:

readfile('Application.app');

因为您没有输出文件内容。

答案 2 :(得分:0)

<?php
$file = "http://example.com/application.app"; 

header("Content-Description: File Transfer"); 
header("Content-Type: application/zip");  // proper octet-stream
header("Content-Disposition: attachment; filename=\"$file\""); 

readfile ($file); 
?>

如果文件未在浏览器中打开..

<?php header("Location: http://example.com/application.app"); ?>