Possible to download a file through the Zend HTTP Client?

三世轮回 提交于 2019-12-12 23:04:08

问题


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


回答1:


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



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/3173390/possible-to-download-a-file-through-the-zend-http-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!