Home > Backend Development > PHP Tutorial > Analysis of the difference between php file_exists is_file and is_dir functions

Analysis of the difference between php file_exists is_file and is_dir functions

WBOY
Release: 2016-07-25 09:00:43
Original
1133 people have browsed it
Let me introduce to you the differences between the three file or directory judgment functions in PHP: file_exists, is_dir, and is_file. Friends who are interested can learn more.

Someone said that PHP's file_exists = is_dir + is_file, haha, why do you say class like this?

The file_exists function can not only determine whether the file exists, but also determine whether the directory exists. However, its execution efficiency is very low, just like the request in ASP does not specify whether it is a form, get, or cookies. Therefore, if you are smart, you will be able to smoothly understand the following summary:

1. If you want to determine whether the directory exists, please use the independent function is_dir(directory) 2. If you want to determine whether the file exists, please use the independent function is_file(filepath)

3. is_file only determines whether the file exists; file_exists determines whether the file exists or whether the directory exists; is_dir determines whether the directory exists;

The results of these two functions will be cached, but is_file will be many times faster and more efficient.

Highlights that I have to mention: 1. When the file exists, is_file is N times faster than file_exists; 2. When the file does not exist, is_file is slower than file_exists;

Therefore, the file_exits function will not affect the speed depending on whether the file actually exists, but is_file is greatly affected by this.

With the above difference analysis, I believe you already have your own idea when choosing which function to use, good luck!!!

welcome to bbs.it-home.org.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template