The definition and use of is_dir() function in PHP

墨辰丷
Release: 2023-03-31 12:58:02
Original
1993 people have browsed it

php provides the built-in function is_dir to check whether the incoming path parameter is a directory, and returns true if it is a directory. That is to say, if the parameter passed in is a file or does not exist, it will be false, so the current parameter cannot be said to be either a folder or a file. Another thing to note is that parameters support relative paths and absolute paths.

Function: is_dir()

Function: Determine whether the 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, its relative path is checked according to the current working directory.

Note: The results of this function will be cached. See clearstatcache() for more information.

Example 1

<?
var_dump(is_dir(&#39;a_file.txt&#39;)) . "\n";
var_dump(is_dir(&#39;bogus_dir/abc&#39;)) . "\n";
var_dump(is_dir(&#39;..&#39;)); //one dir up
?>
Copy after login

The above example 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");
}
?>
Copy after login

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

Summary: The above is the summary of this article All content, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implements the method of extracting Chinese and English initials

php creates an intelligent Methods of histogram program

Definition and usage of PHP header

The above is the detailed content of The definition and use of is_dir() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!