Home  >  Article  >  Backend Development  >  PHP is_dir() 判断给定文件名是否是一个目录_PHP

PHP is_dir() 判断给定文件名是否是一个目录_PHP

WBOY
WBOYOriginal
2016-06-01 12:18:14715browse

说明
bool is_dir ( string $filename )
如果文件名存在并且为目录则返回 TRUE。如果 filename 是一个相对路径,则按照当前工作目录检查其相对路径。

Note: 本函数的结果会被缓存。更多信息参见 clearstatcache()。

is_dir() 例子1
复制代码 代码如下:

var_dump(is_dir('a_file.txt')) . "\n";
var_dump(is_dir('bogus_dir/abc')) . "\n";
var_dump(is_dir('..')); //one dir up
?>

上例将输出:

bool(false)
bool(false)
bool(true)

is_dir() 例子2
复制代码 代码如下:
$file = "images";
if(is_dir($file))
{
echo ("$file is a directory");
}
else
{
echo ("$file is not a directory");
}
?>

输出:
如果存在images这个目录,则输出如下。
images is a directory

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