cURL functions
| From: | Chris Bruce | Date: | Thu, 12 May 2005 18:54:20 +0000 |
| Subject: | cURL functions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-215059@lists.php.net to get a copy of this message | ||
Hi,
I am connecting to a remote image download API using cURL functions. I have the connection working fine and am getting the response from the API. The problem is that the resulting image is being displayed as binary characters in the browser instead of downloading to my computer. Here is the code:
$ch = curl_init(); // create cURL handle (ch)
if (!$ch) {
die("Couldn't initialize a cURL handle");
}
// set some cURL options
$ret = curl_setopt($ch, CURLOPT_URL, "path/to/api/with/vars/appended");
$ret = curl_setopt($ch, CURLOPT_HEADER, 0);
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$ret = curl_setopt($ch, CURLOPT_TIMEOUT, 30);
// execute
$ret = curl_exec($ch);
and here are the results from curl_getinfo:
Array
(
[url] => path/to/api/with/vars/appended
[http_code] => 200
[header_size] => 312
[request_size] => 242
[filetime] => -1
[ssl_verify_result] => 0
[total_time] => 0.298
[namelookup_time] => 0.013
[connect_time] => 0.013
[pretransfer_time] => 0.013
[size_upload] => 0
[size_download] => 750690
[speed_download] => 2519093.9597315
[speed_upload] => 0
[download_content_length] => 750690
[upload_content_length] => 0
)
Does anyone know how I can take the binary result and force it to download as a JPG image?
Thanks.
Chris