Page 1 of 1

file_exists problem

Posted: Wed Jun 07, 2006 2:19 pm
by bluesman333
I'm trying to use the file_exists function to check that an image exists before displaying a link.

Code: Select all

function image_exists($image_name) {
  
   $dir = "http://domain.com/images/";
 
     if(file_exists($dir.$image_name) {
          return true;
     }else{
          return false;
     }

}

It's always returning false - even if the image exists.


Any suggestions?

Posted: Wed Jun 07, 2006 2:26 pm
by pickle
I'm pretty sure you can't use URL wrappers with file_exists(). Are you trying to check if an image exists on another server?

Posted: Wed Jun 07, 2006 2:28 pm
by TheMoose
As pickle said, you can't use file_exists doesn't have the wrappers.

Try something like:

Code: Select all

function image_exists($image_name) {
	$dir = "http://domain.com/images/";
	$f = fopen($dir.$image_name, "r");
	if(!$f) return false;
	fclose($f);
	return true;
}