11 08 2015

34. 根据 URL 下载图片

?
1
2
3
4
5
6
7
8
9
10
11
12
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);
}

语法:

?
1
2
3
4
5
<?php
$url = "http://koonk.com/images/logo.png";
$rename = "koonk.png";
imagefromURL($url,$rename);
?>
发表评论