[英]How can I count all files in a directory with PHP? (e.g. 124 Files)
I'm trying to figure out how I can count all of my XML files in one directory. 我试图弄清楚如何在一个目录中计算所有XML文件。 How can I do this with PHP? 我该如何使用PHP?
$dir = "random_directory/";
$files = glob("$dir*.xml");
$count = $files !== false ? count($files) : 0;
echo $count;
Just change $dir to your directory. 只需将$ dir更改为目录即可。
$files = scandir('/path/to/dir/');
$count = 0;
foreach ($files as $file) {
if (strtolower(substr($file, 4)) == '.xml') {
$count++;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.