我正在创建一个网站,当用户搜索图像下载链接将出现但我无法使用PHP为此目的。 Allow user to download external image PHP 以上链接有想法,但我怎么能这样做,请给出正确的方法。
答案 0 :(得分:0)
有很多方法最好的一个是CURL 但要注意安全!你必须检查Mime类型(its possible with exif)
function grab_image($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
return $raw;
}
另一种方式是file_get_contents