I am trying to build a script where it downloads a file using the Zend http client: http://framework.zend.com/manual/en/zend.http.html but I can't find anywhere where it says how to do this so I'm wondering if its possible... The file is dependent on being logged in so I need to have it done through the zend http client so it can make use of the cooki开发者_如何学Ces that are created when the script logs in..
any advice is greatly appreciated
Complete the request for the file just like you would a webpage. The body of the response should contain the binary data for the file (or possibly text data if you were downloading a CSS, XML, etc... file).
$body = $response->getBody();
file_put_contents("myfile.zip",$body);
Example #11 Receiving file from HTTP server with streaming
$client->setStreaming(); // will use temp file
$response = $client->request('GET');
// copy file
copy($response->getStreamName(), "my/downloads/file");
// use stream
$fp = fopen("my/downloads/file2", "w");
stream_copy_to_stream($response->getStream(), $fp);
// Also can write to known file
$client->setStreaming("my/downloads/myfile)->request('GET');
http://framework.zend.com/manual/en/zend.http.client.advanced.html
last example
Personally, I would use cURL instead.
cURL in the PHP manual: http://php.net/manual/en/book.curl.php
A simple example of using cURL to download a file: http://www.webdigity.com/index.php?action=tutorial;code=45
精彩评论