Linux 拨号vps windows公众号手机端

php获取文件列表的方法有哪些

lewis 9年前 (2016-12-14) 阅读数 9 #程序编程
文章标签 PHP

  1. 使用PHP的glob()函数可以获取满足指定模式的文件列表,例如:
$files = glob('path/to/directory/*');
foreach ($files as $file) {
    echo $file . "<br>";
}
  1. 使用PHP的scandir()函数可以获取目录中的文件列表,例如:
$files = scandir('path/to/directory');
foreach ($files as $file) {
    echo $file . "<br>";
}
  1. 使用PHP的opendir()、readdir()和closedir()函数可以打开目录、读取文件列表并关闭目录,例如:
$dir = 'path/to/directory';
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo $file . "<br>";
        }
    }
    closedir($handle);
}

这些方法都可以用来获取目录中的文件列表,选择适合自己需求的方式来获取文件列表。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门