如何计算PHP文件夹中的文件数? [英] How to count number of files in folder in php?

查看:88
本文介绍了如何计算PHP文件夹中的文件数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用户能够在自己的文件夹中上传一些文件(图片)。但这仅在该文件夹包含少于五张图片的情况下才有可能。如果已经有5张图片,脚本必须让用户知道他/她的文件夹已满。
所以,我想知道php中是否有函数计算文件夹中文件的数量。或在PHP中的任何其他方式做到这一点?提前致谢。

I want to enable users to upload some files (pictures) in their own folders. But that should be possible only if that folders contain less than five pictures. If there are 5 pictures already, script has to let know user that his/her folder is full. So, I wonder if there is function in php that count number of files in folder. Or any other way in php to do that? Thanks in advance.

推荐答案

使用 FilesystemIterator ,如下所示:

$dir = "/path/to/folder";
$fi = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS);
$fileCount = iterator_count($fi);

这篇关于如何计算PHP文件夹中的文件数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆