Take the 2-minute tour ×

I have code using file_exists getting called from two different files. The problem is that when called from one file, the function works as expected. Called from the other file, it always returns false.

I've verified the filepaths getting called are the same. I've also checked permissions for the files as well and they are the same. Any ideas as to why the following code would work with one file and not the other?

$filepath = "{$Globals['datafull']}$thecat/thumbs/$bigimage";
$fileurl = "{$Globals['datadir']}/$thecat/thumbs/$bigimage";

$imgtag = "<img border=\"0\" $imgsize src=\"{$Globals['idir']}/nothumb.gif\" alt=\"$fileurl\" />";

$rand = ( $nocache == 1 ? "?".rand(0,9999) : null );

if ( file_exists($filepath) )
   if ( VB40 == "on" && $avatar == 1 )
        $imgtag = "<img class=\"forumicon\" title=\"$title\" border=\"0\" width=\"50\" height=\"37\" src=\"$fileurl$rand\" alt=\"$bigimage\" />";
        $imgtag = "<img title=\"$title\" border=\"0\" $imgsize src=\"$fileurl$rand\" alt=\"$bigimage\" />";
    $thumbtag = $fileurl;

    $theext = strtolower( $theext );
    $filepath2 = "{$Globals['datafull']}$thecat/thumbs/$product_name.jpg";
    $fileurl2 = "{$Globals['datadir']}/$thecat/thumbs/$product_name.jpg$rand";

    if ( file_exists($filepath2) )
        $imgtag = "<img title=\"$title\" border=\"0\" $imgsize src=\"$fileurl2$rand\" alt=\"$bigimage\" />";
        $thumbtag = $fileurl2;


share|improve this question
You refer maybe to the files with relative pathnames and both scripts are in different directories ? –  fyr Jun 28 '11 at 19:17
In the case where this script does not work: do you include the file from inside a function? If yes, do you explicitly use global $Globals; to make your used global variable visible? –  ZeissS Jun 28 '11 at 19:17
not exactly related, but keep in mind, that the result from file_exists is cached and you may need to call clearstatcache before file_exists –  Darhazer Jun 28 '11 at 19:30
Fyr - I'm referring to the files with absolute path names. –  Yazmin Jun 28 '11 at 19:32
ZiessS - No, but I have echoed the filepaths to make sure the variable is visible and the values are correct so the files should be found. –  Yazmin Jun 28 '11 at 19:32
add comment

Your Answer



Browse other questions tagged or ask your own question.