Php uses curl to determine whether an image or page is complete
Source: Internet
Author: User
Using curl in php to determine whether an image or page is complete in PHP is a good thing. curl can be used to determine whether a file or page can be opened, such as functioncheck_url ($ url) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_s php uses curl to determine whether the image or page is complete
In PHP, curl is a good thing and can be used to determine whether a file or page can be opened. for example:
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 = '20140901 ')
Echo "Its works ";
Else
Echo "broken url ";
We can see that this method uses curl to retrieve the status of the http header.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service