I am developing a site where users submit links and they specify an image from that link to be used as a thumbnail. The image will be saved from the webpage, not uploaded by the user.
It seems like I have two options to do this and they are file_get_contents
and cURL
file_get_contents example:
$url = 'http://example.com/file_name.jpg';
$img = '/path/file_name.jpg';
file_put_contents($image, file_get_contents($url));
cURL example:
$ch = curl_init('http://example.com/file_name.jpg');
$fp = fopen('/path/file_name.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
In terms of reliability and security, which is preferred? What security concerns does fetching a remote file using the methods present and how can I protect against them?
I am using Codeigniter if there are any classes or functions that would help with this.