The difference between file_exists and is_file is_dir in PHP

  • 2020-05-24 05:16:24
  • OfStack

file_exists is obviously influenced by asp, because asp not only has fileExists but also folderExists,driverExists, so what does file_exists mean in PHP?

file_exists = is_dir + is_file

It can determine the existence of both files and directories. However, such a comprehensive function is very inefficient in execution. For example, in asp, request does not specify whether it is form or get or cookies, so the conclusion is:

The & # 9702; To determine if a directory exists, use the independent function is_dir(directory)
The & # 9702; To determine if a file exists, use the standalone function is_file(filepath)

is_file only determines if the file exists;
file_exists determines whether a file exists or whether a directory exists;
is_dir determines whether the directory exists;

Looking at the manual, the results of both functions are cached, but is_file is N times faster.
One more note:
If the file exists, is_file is N times faster than file_exists.
If the file does not exist, is_file is slower than file_exists;
The conclusion is that the file_exits function does not affect the speed due to whether the file actually exists, but the is_file function does.

Related articles: