0

How i will check that a particular image with given path exists on another server or not? I have the following code in which i used file get contents but that is taking so long time and due to that sometimes jquery stops working.

function is_file_url_exists($url) 
{
    if (@file_get_contents($url, 0, NULL, 0, 1)) 
    {
        return 1;
    }
    return 0;           
}
TECHNOMAN
  • 361
  • 1
  • 9

1 Answers1

0

Why dont you use php bbuiltin function file_exists?

if (file_exists($url)) {   
   return 1;                     
}
else
   return 0;

Or You can also use:

$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
   $exists = false;
}
else {
   $exists = true;
}

Source: http://php.net/manual/en/function.file-exists.php

Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24