Search code examples
phpfile-exists

File exists always returning false


My image directory is \webroot\files\thumbs

I am trying to add file_exists condition. For that I tried bellow code

$file = WWW_ROOT .'files' . DS . 'thumbs' . DS .'_'.$password->collection_id.'jpg';

$file_exists = file_exists($file);

It's always returning zero.

If I echo $file it's giving me output like this

c:\xampp\htdocs\myproject\files\thumbs\_61.jpg

Solution

  • You're missing the . before the extension. Update your $file definition as follows:

    $file = WWW_ROOT .'files' . DS . 'thumbs' . DS .'_'.$password->collection_id.'.jpg';
                                                           // This was missing ---^
    
    $file_exists = file_exists($file);