PHP下载脚本

时间:2011-03-03 07:03:20

标签: php download

[编辑]我正在尝试创建一个下载文件的脚本,问题是我正在访问生成该文件的页面(来自网络上的服务器)(打开下载窗口)。有没有办法让我在php中弹出这个文件?注意:我无法修改生成页面...这是一个excel文件。该应用程序称为Cognos。我使用opera来查看页面变量已解析,因此我可以访问下载页面,但我必须在没有下载弹出窗口的文件夹中进行下载

1 个答案:

答案 0 :(得分:0)

您可以强制下载标题。

// Define the path to file
$file = file_get_contents('path/to/file_creating_script.php');

// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=RandomFileName");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");

// Read the file from disk
echo $file;

我还没有测试过这个版本的脚本。