David David - 9 months ago 33
PHP Question

How to check if a file exists from a url

I need to check if a particular file exists on a remote server. Using

is_file()
and
file_exists()
doesn't work. Any ideas how to do this quickly and easily?

Answer Source

you have to use CURL

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);

    if($code == 200){
       $status = true;
    }else{
      $status = false;
    }
    curl_close($ch);
   return $status;
}