Home >Backend Development >PHP Tutorial >Guide to using is_dir() function in PHP_PHP Tutorial

Guide to using is_dir() function in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:54:351113browse

Guide to the use of is_dir() function in PHP

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 filename exists and is a directory.

If filename is a relative path, its relative path is checked against the current working directory.

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

Example 1

ใ€€?

1

2

3

4

5

var_dump(is_dir('a_file.txt')) . "n";

var_dump(is_dir('bogus_dir/abc')) . "n";

var_dump(is_dir('..')); //one dir up

?>

1

2

3

4

5

1

2

3

4

5

6

7

8

9

10

11

$file = "images";

if(is_dir($file))

{

echo ("$file is a directory");

}

else

{

echo ("$file is not a directory");

}

?>

var_dump(is_dir('a_file.txt')) . "n";

var_dump(is_dir('bogus_dir/abc')) . "n";

var_dump(is_dir('..')); //one dir up

?>

The above example will output:

bool(false)

bool(true) Example 2 ใ€€?
1 2 3 4
5 6 7 8 9 10 11
<๐ŸŽœ>$file = "images";<๐ŸŽœ> <๐ŸŽœ>if(is_dir($file))<๐ŸŽœ> <๐ŸŽœ>{<๐ŸŽœ> <๐ŸŽœ>echo ("$file is a directory");<๐ŸŽœ> <๐ŸŽœ>}<๐ŸŽœ> <๐ŸŽœ>else<๐ŸŽœ> <๐ŸŽœ>{<๐ŸŽœ> <๐ŸŽœ>echo ("$file is not a directory");<๐ŸŽœ> <๐ŸŽœ>}<๐ŸŽœ> <๐ŸŽœ>?>
Output: If the images directory exists, output: ใ€€images is a directory The above is the entire content of this article, I hope you all like it. http://www.bkjia.com/PHPjc/996756.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/996756.htmlTechArticleGuide to the use of is_dir() function in PHP. PHP provides the built-in function is_dir to check whether the incoming path parameter is a directory. Returns true if it is a directory. That is to say, the parameter passed in is a file or not...
Statement๏ผš
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