Skip to content
Advertisement

is_file or file_exists in PHP

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?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement