opendir() 函数打开目录句柄。成功则返回目录句柄资源。失败则返回 false。如果路径不是合法目录,或者由于许可限制或文件系统错误导致的目录不能打开,则抛出 e_warning 级别的错误。您可以通过在函数名称前添加 '@' 来隐藏 opendir() 的错误输出
opendir() 函数语法
opendir(path,context);
| 参数 | 描述 |
|---|---|
| path | 必需。规定要打开的目录路径。 |
| context | 可选。规定目录句柄的环境。context 是可修改目录流的行为的一套选项。 |
opendir() 函数实例,代码如下:
$dirs ='./';//指定当前上当
if( is_dir( $dirs ) )
{
$hanld = opendir($dirs);
while (($file = readdir($hanld)) !== false)
{
echo "文件名: " . $file . "<br />";
}
closedir($hanld);
}
else
{
echo '不是目录';
}输出结果:
文件名:a
文件名:b
文件名:www.php.cn
以上就是php中opendir函数的简单用法说明?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号