Definition and use of is_dir () function in PHP

Source: Internet
Author: User
PHP provides built-in function is_dir to check if the passed-in Path parameter is a directory and returns true if it is a directory. This means that the parameter passed in is either a file or not, so the current parameter cannot be said to be a folder or a file. It is also important to note that the parameters support relative paths and absolute paths.

Function: Is_dir ()

Function: Determine if a given file name is a directory

Description
BOOL Is_dir (String $filename)

Returns TRUE if the file name exists and is a directory.
If filename is a relative path, the relative path is checked according to the current working directory.

Note: The result of this function is cached. See Clearstatcache () for more information.

Example 1

<?var_dump (Is_dir (' A_file.txt ')). "\ n"; Var_dump (Is_dir (' bogus_dir/abc ')). "\ n"; Var_dump (Is_dir ('. ')); One dir up?>

The example above will output:

BOOL (FALSE)
BOOL (FALSE)
BOOL (TRUE)

Example 2

<?php$file = "Images", if (Is_dir ($file)) {echo ("$file is a Directory");} Else{echo ("$file is not a directory"); >

Output:
If the directory exists images, the output is:
Images is a directory

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP implementation method of extracting Chinese and English initial letters

How to build an intelligent bar chart program in PHP

The definition and usage of headers in PHP header

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.