当前位置:网站首页>PHP 统计指定文件夹下文件的数量
PHP 统计指定文件夹下文件的数量
2022-04-23 04:46:00 【yizecellophp】
<?php
//给我一个文件夹,返回该文件夹下所有的文件数量
function ShuLiang($url)//造一个方法,给一个参数
{
$sl=0;//造一个变量,让他默认值为0;
$arr = glob($url);//把该路径下所有的文件存到一个数组里面;
foreach ($arr as $v)//循环便利一下,吧数组$arr赋给$v;
{
if(is_file($v))//先用个if判断一下这个文件夹下的文件是不是文件,有可能是文件夹;
{
$sl++;//如果是文件,数量加一;
}
else
{
$sl+=ShuLiang($v."/*");//如果是文件夹,那么再调用函数本身获取此文件夹下文件的数量,这种方法称为递归;
}
}
return $sl;//当这个方法走完后,返回一个值$sl,这个值就是该路径下所有的文件数量;
}
echo ShuLiang("upload/*");//用这个方法查一下该路径下所有的文件数量 根目录下的文件名即可;
?>
版权声明
本文为[yizecellophp]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Celloda/article/details/124302358
边栏推荐
- The object needs to add additional attributes. There is no need to add attributes in the entity. The required information is returned
- Ali's ten-year technical experts jointly created the "latest" jetpack compose project combat drill (with demo)
- Alibaba tip: it is better to create threads manually
- Spark optimization
- leetcode003--判断一个整数是否为回文数
- Record the ThreadPoolExecutor main thread waiting for sub threads
- QML advanced (V) - realize all kinds of cool special effects through particle simulation system
- test
- Programmers complain: I really can't live with a salary of 12000. Netizen: how can I say 3000
- Eight misunderstandings that should be avoided in data visualization
猜你喜欢
QML advanced (IV) - drawing custom controls
程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说
Recommended scheme of national manufactured electronic components for intelligent electronic scales
Painless upgrade of pixel series
Installation du compilateur croisé de la plateforme zynq
Chapter 4 - understanding standard equipment documents, filters and pipelines
What is a data island? Why is there still a data island in 2022?
Phishing for NFT
QML进阶(四)-绘制自定义控件
Introduction to raspberry pie 3B - system installation
随机推荐
Spark small case - RDD, broadcast
The programmer starts the required application with one click of window bat
補:注解(Annotation)
What's the difference between error and exception
Migrate from MySQL database to AWS dynamodb
Custom switch control
Jetpack -- lifecycle usage and source code analysis
Huawei machine test -- high precision integer addition
Recommended scheme of national manufactured electronic components
补充番外14:cmake实践项目笔记(未完待续4/22)
Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
leetcode003--判断一个整数是否为回文数
Unity rawimage background seamlessly connected mobile
Differences among electric drill, electric hammer and electric pick
FAQ of foreign lead and alliance Manager
程序员抱怨:1万2的工资我真的活不下去了,网友:我3千咋说
CLion+OpenCV identify ID number - detect ID number
第四章 --- 了解标准设备文件、过滤器和管道
Key points of AWS eks deployment and differences between console and eksctl creation
Supplement: Annotation