【发布时间】:2012-11-09 19:28:57
【问题描述】:
我正在开发一个网站,用户可以在其中提交链接,并指定该链接中的图像用作缩略图。图片将从网页中保存,而不是由用户上传。
看来我有两个选项可以做到这一点,它们是file_get_contents 和 cURL
file_get_contents 示例:
$url = 'http://example.com/file_name.jpg';
$img = '/path/file_name.jpg';
file_put_contents($image, file_get_contents($url));
cURL 示例:
$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);
在可靠性和安全性方面,哪个更受欢迎?使用现有方法获取远程文件有哪些安全问题,我该如何防范?
如果有任何有助于解决此问题的类或函数,我正在使用 Codeigniter。
【问题讨论】:
标签: php codeigniter