How to check if a file exists from a url
You don't need CURL for that... Too much overhead for just wanting to check if a file exists or not...
Use PHP's get_header.
$headers=get_headers($url);
Then check if $result[0] contains 200 OK (which means the file is there)
A function to check if a URL works could be this:
function UR_exists($url){ $headers=get_headers($url); return stripos($headers[0],"200 OK")?true:false;}/* You can test a URL like this (sample) */if(UR_exists("http://www.amazingjokes.com/")) echo "This page exists";else echo "This page does not exist";
You have to use CURL
function does_url_exists($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;}
I've just found this solution:
if(@getimagesize($remoteImageURL)){ //image exists!}else{ //image does not exist.}
Source: http://www.dreamincode.net/forums/topic/11197-checking-if-file-exists-on-remote-server/