Home >Backend Development >PHP Tutorial > php顶用curl去判断图片或页面是否完整
php中用curl去判断图片或页面是否完整
在PHP中,curl是个好东西,可以用来判断是否能打开某个文件或者页面,比如:
function check_url($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
return $headers['http_code'];
}
$myurl = "http://www.XXX/XXX.JPG";
$satus = check_url($myurl);
if($satus == '200')
echo "Its works";
else
echo "broken url";
可以看到,这个方法是用curl去取出http头的状态的