当前位置 : 主页 > 网络编程 > PHP >

PHP根据 URL 下载图片

来源:互联网 收集:自由互联 发布时间:2021-06-30
function imagefromURL($image,$rename){$ch = curl_init($image);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);$rawdata=curl_exec ($ch);curl_close ($ch);$fp = fopen("
function imagefromURL($image,$rename)
{
$ch = curl_init($image);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("$rename",'w');
fwrite($fp, $rawdata); 
fclose($fp);
}

用法:
<?php
$url = "http://koonk.com/images/logo.png";
$rename = "koonk.png";
imagefromURL($url,$rename);
?>
网友评论