开发者

PHP Download Script

开发者 https://www.devze.com 2023-02-14 07:51 出处:网络
[edited] I am trying to make a script that downloads a file, the problem is that i am accesing a page(from a server on the network) that generates that file (opens a download window). Is there a way I

[edited] I am trying to make a script that downloads a file, the problem is that i am accesing a page(from a server on the network) that generates that file (opens a download window). Is there a way I can get that file witought that pop-up in php? NOTE: I cannot modify the generating page... It is an excel file. The application is called Cognos. I managed with opera to see page variables parsed so I can get to the download page but I must make that download in a folder witho开发者_高级运维ut the download pop-up


You can force a download with headers.

// 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;

I haven't tested this version of the script though.

0

精彩评论

暂无评论...
验证码 换一张
取 消