Home >Backend Development >PHP Tutorial > php顶用curl去判断图片或页面是否完整

php顶用curl去判断图片或页面是否完整

WBOY
WBOYOriginal
2016-06-13 13:09:08944browse

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头的状态的

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn