使用PHP获取目录中的所有文件的名称 [英] Getting the names of all files in a directory with PHP
本文介绍了使用PHP获取目录中的所有文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于某种原因,我使用以下代码为文件名保持1:
For some reason, I keep getting a '1' for the file names with this code:
if (is_dir($log_directory))
{
if ($handle = opendir($log_directory))
{
while($file = readdir($handle) !== FALSE)
{
$results_array[] = $file;
}
closedir($handle);
}
}
当我回调$ results_array中的每个元素时,我得到一堆'1',而不是文件的名称。如何获取文件的名称?
When I echo each element in $results_array, I get a bunch of '1's, not the name of the file. How do I get the name of the files?
推荐答案
不要打扰/ readdir并使用 glob
:
Don't bother with open/readdir and use glob
instead:
foreach(glob($log_directory.'/*.*') as $file) {
...
}
这篇关于使用PHP获取目录中的所有文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文