Introduction to the difference between file_exists and Is_file,is_dir in PHP

Source: Internet
Author: User
Introduction to the difference between file_exists and Is_file,is_dir in PHP

Font: [Increase decrease] Type: Reprint time: 2012-09-12 I want to comment

Obviously file_exists is affected by the ASP, because the ASP not only has fileexists and folderexists,driverexists, so what is the meaning of file_exists in PHP is obviously file_ exists is affected by the ASP, because the ASP not only has FileExists and folderexists,driverexists, then what does PHP file_exists mean?

PHP file_exists = is_dir + is_file

It can determine whether a file exists, or whether the directory exists. But such a comprehensive function execution is very inefficient, just as the request in ASP does not specify a form, or get,cookies, so the conclusion is:

◦ If you want to determine if the directory exists, use the standalone function Is_dir (directory)
◦ If you want to determine if the file exists, use the standalone function is_file (filepath)

Is_file only determine if the file exists;
File_exists determine whether the file exists or whether the directory exists;
Is_dir determine whether the directory exists;

Look at the manual, although the results of both functions are cached, but the is_file is almost n times faster.
There is one more notable:
In the case of file existence, Is_file is faster n times 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 speed because the file really exists, but the is_file effect is large.

Introduction to the difference between file_exists and Is_file,is_dir in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.