更新时间:2021-12-09 08:29:13
当然有可能.查看 opendir的文档,然后将每个文件推送到结果数组.如果您使用的是PHP5,请查看 DirectoryIterator .这是遍历目录内容的一种更流畅,更干净的方法!
It's certainly possible. Have a look at the documentation for opendir and push every file to a result array. If you're using PHP5, have a look at DirectoryIterator. It is a much smoother and cleaner way to traverse the contents of a directory!
编辑:建立在 opendir 上:
$dir = "/etc/php5/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
$images = array();
while (($file = readdir($dh)) !== false) {
if (!is_dir($dir.$file)) {
$images[] = $file;
}
}
closedir($dh);
print_r($images);
}
}