🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
glob:// — 查找匹配的文件路径模式 **封装协议摘要** | 属性 | 支持 | | --- | --- | | 受限于[allow\_url\_fopen](https://www.php.net/manual/zh/filesystem.configuration.php#ini.allow-url-fopen) | No | | 受限于[allow\_url\_include](https://www.php.net/manual/zh/filesystem.configuration.php#ini.allow-url-include) | No | | 允许读取 | No | | 允许写入 | No | | 允许附加 | No | | 允许同时读写 | No | | 支持[stat()](https://www.php.net/manual/zh/function.stat.php) | No | | 支持[unlink()](https://www.php.net/manual/zh/function.unlink.php) | No | | 支持[rename()](https://www.php.net/manual/zh/function.rename.php) | No | | 支持[mkdir()](https://www.php.net/manual/zh/function.mkdir.php) | No | | 支持[rmdir()](https://www.php.net/manual/zh/function.rmdir.php) | No | ``` <?php $it = new DirectoryIterator($_GET['file']); foreach($it as $f) { printf("%s", $f->getFilename()); echo'</br>'; } ?> ``` ![](https://img.kancloud.cn/88/dd/88dd73a506081abd988a805083237e92_572x272.png) ``` // 循环 ext/spl/examples/ 目录里所有 *.php 文件 // 并打印文件名和文件尺寸 $it = new DirectoryIterator("glob://ext/spl/examples/*.php"); foreach($it as $f) { printf("%s: %.1FK\n", $f->getFilename(), $f->getSize()/1024); } 输出: tree.php: 1.0K findregex.php: 0.6K findfile.php: 0.7K dba_dump.php: 0.9K nocvsdir.php: 1.1K phar_from_dir.php: 1.0K ini_groups.php: 0.9K directorytree.php: 0.9K dba_array.php: 1.1K class_tree.php: 1.8K ```