CodeIgniter Forums
Copy a remote image with copy(). Good or bad? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Copy a remote image with copy(). Good or bad? (/showthread.php?tid=10521)



Copy a remote image with copy(). Good or bad? - El Forum - 08-03-2008

[eluser]codex[/eluser]
I want to grab images from a remote source. Copy() seems to work fine, but I was wondering if copy() is the best function for this. Is there a better/more efficient way?


Copy a remote image with copy(). Good or bad? - El Forum - 08-03-2008

[eluser]codex[/eluser]
curl seems to do a better job.

Code:
$file_name = $this->input->post('image_src');
$md5 = md5($file_name . rand());
            
$ch = curl_init($file_name);
$fp = fopen('./assets/photos/'. $md5 .'.jpg', 'w');
            
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
            
curl_exec($ch);
curl_close($ch);
fclose($fp);