Title: PHP function file_exists problems
Last modified: August 19, 2016

---

# PHP function file_exists problems

 *  [kilolima](https://wordpress.org/support/users/kilolima/)
 * (@kilolima)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/php-function-file_exists-problems/)
 * 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)

 *  [Michael Fields](https://wordpress.org/support/users/mfields/)
 * (@mfields)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/php-function-file_exists-problems/#post-957528)
 * 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](https://wordpress.org/support/users/kilolima/)
 * (@kilolima)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/php-function-file_exists-problems/#post-957582)
 * 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.

 * 2 replies
 * 2 participants
 * Last reply from: [kilolima](https://wordpress.org/support/users/kilolima/)
 * Last activity: [17 years, 5 months ago](https://wordpress.org/support/topic/php-function-file_exists-problems/#post-957582)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
