PHP:如何在目录中列出文件而不列出子目录 [英] PHP: How to list files in a directory without listing subdirectories
本文介绍了PHP:如何在目录中列出文件而不列出子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码的开始部分,用于列出目录中的文件:
This is the starting portion of my code to list files in a directory:
$files = scandir($dir);
$array = array();
foreach($files as $file)
{
if($file != '.' && $file != '..' && !is_dir($file)){
....
我正在尝试列出目录中的所有文件而不列出子文件夹.该代码有效,但同时显示文件和文件夹.正如您在上面的代码中看到的那样,我添加了!is_dir($file)
,但是结果仍然相同.
I'm trying to list all files in a directory without listing subfolders. The code is working, but showing both files and folders. I added !is_dir($file)
as you see in my code above, but the results are still the same.
推荐答案
我认为应该是这样的
$files = scandir($dir);
foreach($files as $file)
{
if(is_file($dir.$file)){
....
这篇关于PHP:如何在目录中列出文件而不列出子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文