//伪装路径下载图片
function getImg($url = "", $filename = "")
{
//去除URL连接上面可能的引号
//$url = preg_replace( "/(?:^[""]+|[""/]+$)/", "", $url );
$hander = curl_init();
$fp = fopen($filename,"wb");
curl_setopt($hander,CURLOPT_URL,$url);
curl_setopt($hander, CURLOPT_REFERER, "http://www.yy5p.com/");//伪装访问路径
curl_setopt($hander,CURLOPT_FILE,$fp);
curl_setopt($hander,CURLOPT_HEADER,0);
curl_setopt($hander,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($hander,CURLOPT_TIMEOUT,60);
curl_exec($hander);
curl_close($hander);
fclose($fp);
Return true;
}
getImg("http://wvw.dhh9.com/aaa/201411/10405/1.jpg","./image.jpg");
//判断页面404
function http_status($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_exec($ch);
$status = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($status == 404) ? "404" : "no404";
}
echo http_status("http://www.yy5p.com/meinv/");