tags:

views:

1339

answers:

1

Hi there,

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?

+10  A: 

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().

htw
as far as i know, if_file also fails for symbolic links, not only directories.
Schnalle
I believe it tries to resolve symlinks, although I'm not 100% sure.
htw
Just ran a quick test, and it indeed resolves the symlink.
htw