PHP opendir() 函数
实例
<?php $dir = "/images/"; // Open a directory, and read its contents if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh)) !== false){ echo "filename:" . $file . "<br>"; } closedir($dh); } } ?>
效果
filename: cat.gif filename: dog.gif filename: horse.gif
定义和用法
opendir() 函数翻开目次句柄。
语法
opendir(path,context);
参数 | 形貌 |
---|---|
path | 必须。划定要翻开的目次途径。 |
context | 可选。划定目次句柄的环境。context 是可修正目次流的行动的一套选项。 |
技术细节
返回值: | 胜利则返回目次句柄资本。失利则返回 FALSE。假如途径不是正当目次,或许因为允许限定或文件体系毛病致使的目次不能翻开,则抛出 E_WARNING 级别的毛病。您能够经由过程在函数称号前增加 '@' 来隐蔽 opendir() 的毛病输出。 |
---|---|
PHP 版本: | 4.0+ |
PHP 更新日记: | PHP 5.0:path 参数支撑 ftp:// URL 封装协定。 |
以上就是PHP中opendir的用法的细致内容,更多请关注ki4网别的相干文章!