is_file or file_exists in PHP

Duncan Benoit picture Duncan Benoit · Apr 27, 2009 · Viewed 54.9k times · Source

I need to check if a file is on HDD at a specified location ($path.$file_name).

Which is the difference between is_file() and file_exists() functions and which is better/faster to use in PHP?

Answer

hbw picture hbw · Apr 27, 2009

is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory. So it would depend entirely on your needs. If you want to know specifically if it's a file or not, use is_file(). Otherwise, use file_exists().