Check Image URL Exists Or Not WIth PHP

How To Image Or Any File Exists Or Not With PHP Language

PHP - Education Funda

For checking the URL is exists or not we can use curl request in PHP and we can use same approach in other programming languages also such as JavaScript.

So for PHP URL check code is below:

function is_url_exist($url){
    $ch = curl_init($url);    
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $status = ($code == 200) ? true : false; // single liner if else
    curl_close($ch);
    return $status;
}


Thanks for reading this blog, I hope it will be helpful for you and please share your feedback in comments section.

Comments

Popular posts from this blog

JavaScript Logical Output Based Interview Questions

Create and Deploy AWS SAM Application

Deploy Angular Build With Express JS Project