We know that PHP provides two built-in functions Is_file, file_exists, can be used in the appropriate situation, to determine whether the file exists, which is good, this article for everyone to make a simple explanation. Look at the following test data, specific examples and see the data, is the most convincing oh. Using Is_file and file_exists to detect the existence of files, respectively, 1000 times to record the time required. File exists (current directory) is_file:0.4570msfile_exists:2.0640ms File exists (absolute path 3 layer/www/hx/a/) is_file:0.4909msfile_exists:3.3500ms File exists (absolute path 5 layer/www/hx/a/b/c/) is_file:0.4961msfile_exists:4.2100ms File does not exist (current directory) is_file:2.0170msfile_exists:1.9848ms File does not exist (absolute path 5 layer/www/hx/a/b/c/) is_file:4.1909msfile_exists:4.1502ms Directory exists file_exists:2.9271msis_dir:0.4601ms directory does not exist FILE_EXISTS:2.9719MSIS_DIR:2.9359MS Is_file ($file) file_exists ($file) when $file is a directory, Is_file returns True False,file_exists In the case of a file, Is_file is much faster than file_exists, and the deeper the directory in which the file is located, the greater the speed difference, but at least 4 times times faster. If the file does not exist, Is_file is a little slower than file_exists, but it can be ignored. In the case of a directory, Is_dir is much faster than file_exists, and Is_dir is a little slower than file_exists in the absence of a directory, but negligible. Believe, smart you, already see, Programmer's home for everyone to make a summary: 1, judge whether the file exists, with function Is_file (), 2, determine whether the directory exists, with the function Is_dir (), 3, not sure the parameters passed in the file or directory, you can consider the next file_exists , or else people are too lonely. |