Saving a remote image with cURL?
Posted
by thebluefox
on Stack Overflow
See other posts from Stack Overflow
or by thebluefox
Published on 2010-05-18T09:11:06Z
Indexed on
2010/05/18
9:20 UTC
Read the original article
Hit count: 264
Morning all,
Theres a few questions around this but none that really answer my question, as far as I ca understand. Basically I have a GD script that deals with resizing and caching images on our server, but I need to do the same with images stored on a remote server.
So, I'm wanting to save the image locally, then resize and display it as normal.
I've got this far...
$file_name_array = explode('/', $filename);
$file_name_array_r = array_reverse($file_name_array);
$save_to = 'system/cache/remote/'.$file_name_array_r[1].'-'.$file_name_array_r[0];
$ch = curl_init($filename);
$fp = fopen($save_to, "wb");
// set URL and other appropriate options
$options = array(CURLOPT_FILE => $fp,
CURLOPT_HEADER => 0,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);
This creates the image file, but does not copy it accross? Am I missing the point?
Cheers guys.
© Stack Overflow or respective owner