直接用fopen下载远程图片
$img=fopen("./mao2.png","w+");
fwrite($img, "http://www.php100.com/uploadfile/2015/0507/thumb_420_240_20150507105744216.png");
使用file_get_content直接下载远程图片
$mao=file_get_contents("http://www.php100.com/uploadfile/2015/0507/thumb_420_240_20150507105744216.png");
file_put_contents("./mao3.png",$mao);
使用fsocket
$headle=fsockopen("www.php100.com",80,$errno,$errstr,30);
if(!$headle)
{
echo "$errstr($errno)<br/>\n";
}else
{
$out="GET /uploadfile/2015/0507/thumb_420_240_20150507105744216.png HTTP/1.1\r\n";
$out.="Host: www.php100.com\r\n";
$out.="Connection: Close\r\n\r\n";
$mao='';
fwrite($headle,$out);//写入
while (!feof($headle)) {
$mao .=fgets($headle,1024);
}
$arr=explode("\r\n\r\n",$mao); //截取返回的重要信息
header("Content-type:image/png");//直接向浏览器输出图片
echo $arr[1];
//fwrite(fopen("./mao4.png","w+"), $arr[1]);//保存图片
curl
初始化curl
$php100=curl_init();
curl_setopt($php100,CURLOPT_URL, "http://www.php100.com/uploadfile/2015/0507/thumb_420_240_20150507105744216.png");
curl_setopt($php100, CURLOPT_RETURNTRANSFER, 1);
curl_exec($php100);
$php=curl_multi_getcontent($php100);
curl_close($php100);
$img=fopen('./mao.png',"w+");
fwrite($img,$php);