cURL functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux