Codeigniter "file_exists($filename)" Codeigniter "file_exists($filename)" codeigniter codeigniter

Codeigniter "file_exists($filename)"


Codeigniter is always running on index.php, so all paths are relative from there. You can use any of the following, assuming upload/ is at the same level as index.php:

  • file_exists("upload/$id.jpg")

  • file_exists("./upload/$id.jpg")

  • file_exists(FCPATH."upload/$id.jpg")

FCPATH is a constant that Codeigniter sets which contains the absolute path to your index.php.

As a side note, I prefer is_file() when checking files, as file_exists() returns true on directories. In addition, you might want to see if getimagesize() returns FALSE to make sure you have an image.