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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:09:08
Original
979 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
curl simulated login
From 1970-01-01 08:00:00
0
0
0
Convert cURL command line to PHP cURL code
From 1970-01-01 08:00:00
0
0
0
Convert command line cURL to PHP cURL
From 1970-01-01 08:00:00
0
0
0
How to set boolean value true in php curl
From 1970-01-01 08:00:00
0
0
0
Please tell me, php curl request page shows blank
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template