php - Saving a remote image with cURL? -


morning in the morning,

There are some questions around this but no one really answers my question As I understand, basically I have a GD script that relates to resizing and caching images on our servers, but I need to do this with the images stored on the remote server.

Therefore, I want to save the image locally, then resize it and display it in general

I have found this very ...

  $ file_name_array = explosion ('/', $ 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 = FOPN ($ Save_to, "YB"); // set URL and other appropriate options $ option = array (CURLOPT_FILE = & gt; $ FP, CURLOPT_HEADER = & gt; 0, CURLOPT_FOLLOWLOCATION = & gt; 1, CURLOPT_TIMEOUT = & gt; 60); // 1 minute timeout (must be enough) curl_setopt_array ($ ch, $ option); Curl_exec ($ ch); Curl_close ($ ch); Fclose ($ FP);  

This creates an image file, but does not copy over it? Am I missing this thing?

Cheers People

More simple, you file_put_contents Instead of can use fwrite :

  $ file_name_array = explosion ('/', $ 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]; File_put_contents ($ save_to, file_get_contents ($ filename));  

or just in 2 rows :)

  $ file_name_array_r = array_reverse (explosion ('/', $ filename)); File_put_contents ('system / cache / remote' '. $ File_name_array_r [1] .'-'. $ File_name_array_r [0], file_get_contents ($ filename));  

Comments