• Hi,

    in my php script within a WP page, a I use a file_exists if statement to check if a variable containing the path of an image thumbnail exists before proceeding. The problem is that even though the image exists and that the path is accurate, file_exists returns false, as does is_file, is_readable, or is_writable. This same image path (wp-content/image_thumbs/thumbname.jpg) works for displaying the same images in html <img> tags later on in the same script. Does file_exists assume a separate path base or is there something else I’m missing here?

    cheers,

    kilolima

Viewing 2 replies - 1 through 2 (of 2 total)
  • The path may not be correct if you are using permalinks. you might try to use the ABSPATH constant. Example:

    <?php file_exists( ABSPATH . /wp-content/image_thumbs/thumbname.jpg ); ?>

    Thread Starter kilolima

    (@kilolima)

    thanks,

    I gave that a try and with the absolute path also manually specified, but it didn’t work either.

    I came up with a horrible work-around. The problem was that a bug in my code would occasionally return an array with the first element unset. After trying to figure out why and failing, and then trying to unset the first array element (which also re-calculates the index thus destroying the array), I thought a simple check to see if the image actually exists would be easiest. When that didn’t work, I created a 1×1 px image named for the first array element, so everything runs, but this is a terribly bad kludge.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP function file_exists problems’ is closed to new replies.