views:

43

answers:

3

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 cookies that are created when the script logs in..

any advice is greatly appreciated

+2  A: 

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

George Marian
I agree. You can use cURL in your controller which already has access to this information.
Colin O'Dell
It's much easier than using the HTTP Client and should generally be available in most PHP configurations.
George Marian
yeah i already use curl but want to use zend because it is hooked up with PHP query which is more powerful than curl, at least for what I am using it for
Rick
@Rick What do you mean by "use zend because it is hooked up with PHP query?" What can't you do by simply modifying the URL provided to cURL?
George Marian
@Rick Look at parse_url() and http_build_query() for dealing w/ the query string parameters programmatically, w/o the hassle of parsing the URL by hand.
George Marian
I'm using PHP query: http://code.google.com/p/phpquery/ and it is built around the Zend http_client, so basically I'm not coming into this saying I prefer to use the zend_http client but rather I want to use PHPquery which offers some advanced features that, as far as I know, aren't available in curl, like you can submit a form in a more "natural" way without having to sniff the http POST, etc.. (but there isn't much written about phpquery or an active user group / forum since its just a port of jquery to php) anyways thanks for the info and I will look into what you said
Rick
+1  A: 

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);
Mike
A: 

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

SM