PHP to determine if a remote picture or file exists

Source: Internet
Author: User
Tags response code

PHP to determine the existence of remote images, this method is also applicable to determine the existence of remote files, which is an efficient and accurate method, it is recommended to use this method, previously used Get_headers () method to determine that there is a problem:

functionCheck_remote_file_exists ($url) {    $curl= Curl_init ($url); //do not retrieve datacurl_setopt ($curl, Curlopt_nobody,true); //Send Request    $result= Curl_exec ($curl); $found=false; if($result!==false) {        //Check if the HTTP response code is        $statusCode= Curl_getinfo ($curl,Curlinfo_http_code); if($statusCode= = 200) {            $found=true; }} curl_close ($curl); return $found;}

From the following example of invocation, the definition variable is assigned with a function return value:

// function Call: $exists = check_remote_file_exists (' http://www.baidu.com/img/baidu_sylogo1.gif '); if ($exists) {    echo ' remote picture exists 'else  {    Echo ' The remote graph does not exist ';}

PHP to determine if a remote picture or file exists

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.