开发者

Save a file to the local server that has a force download header

I 开发者_如何学Goam trying to "copy" a file from a remote server that is being forced to download through the browser. The headers that the remote file outputs are as follows:

HTTP/1.1 200 OK

Server: nginx

Date: Tue, 01 Mar 2011 00:19:21 GMT

Content-Type: application/txt

Content-Length: 170783

Last-Modified: Tue, 01 Mar 2011 00:00:43 GMT

Connection: close

Content-Disposition: attachment; filename="titles.txt"

Expires: Tue, 01 Mar 2011 02:19:21 GMT

Accept-Ranges: bytes

I need some sort of way to override the attachment Content-Disposition so that php can copy the file to the local server. Either that, or some other way of downloading the file from the remote server into the local.

The file to download is a simple text file which would normally be displayed in the browser however I need PHP to "download" it locally as a sort of cache.

I've looked around this site but none of the attempts I've found worked >_<

Any suggestions?!

Thanks in advance, ShadowPuppet


I don't quite follow. You want a server to save a file, but its using the browser?? The following should do what you're after

$file = 'www.exmple.com/mytext.txt';

// Open the file to get existing content

$current = file_get_contents($file);

// Write the contents back to the file

file_put_contents("user/path/to/file/mytext.txt", $current);


At everyone else file_get_contents works even if the server sends content-disposition.

Check your PHP version and its bugs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜