很多站长朋友们都不太清楚php获取文件个数,今天小编就来给大家整理php获取文件个数,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 PHP 获取文件夹内文件数量,要按时间来区别 2、 在php中怎样计算文件夹中的文件数量 3、 php中怎样获取目录中文件的个数? 4、 PHP读取文件夹内有多少个文件 5、 如何用php读取一个文件夹下的文件个数 6、 php 查询文件夹内有多少个文件夹 PHP 获取文件夹内文件数量,要按时间来区别可以使用 filemtime 函数来获得文件的最后修改时间,代码:
<?php
function getFileCounts($dir)
{
$dir = rtrim($dir, DIRECTORY_SEPARATOR.'/'). DIRECTORY_SEPARATOR;
$handle = opendir($dir);
$i = array();
while (false !== $file = (readdir($handle))) {
$path = $dir. $file;
if ($file !== '.' $file != '..' !is_dir($path)) {
$fileTime = @filemtime($path);
if ($fileTime !== false) {
$date = date('Ymd', $fileTime);
isset($i[$date]) ? $i[$date]++ : $i[$date] = 1;
}
}
}
closedir($handle);
return $i;
}
var_dump(getFileCounts("d:"));
请楼主注意代码的正确性哦,看你的代码还是有点乱。
在php中怎样计算文件夹中的文件数量利用scandir函数可以实现,例子代码:
$arr = scandir($dir);
$all = count($arr)-2;//所有文件总数除./和
php中怎样获取目录中文件的个数?$a = count(glob("*",GLOB_ONLYDIR));
$b = count(glob("*"));
echo '当前目录下文件夹数量:',$a,',文件数量:',$b-$a;
//这样就可以获取当前目录的文件夹和文件数量了
PHP读取文件夹内有多少个文件function get_dir_file_count($dir_name){
$dir_file_count =0;
if (is_dir($dir_name)) {
if ($dh = opendir($dir_name)) {
while (($file = readdir($dh)) !== false) {
if($file !='.' $file != '..'){
if(is_file($dir_name.'/'.$file)){
$dir_file_count += 1;
}
if(is_dir($dir_name.'/'.$file)){
//if (isset($this) method_exists($this,'get_dir_size')){
// $dir_file_count += $this->get_dir_file_count($dir_name.'/'.$file);
//} else {
$dir_file_count += get_dir_file_count($dir_name.'/'.$file);
// }
}
}
}
}
closedir($dh);
}
return $dir_file_count;
}
这个是自已写的,网上是没有的。用法:
echo get_dir_file_count('./');
注释的几行是用于class内作为方法使用。就不删除了,作为一个参考。
如何用php读取一个文件夹下的文件个数$arr = scandir('文件夹路径');
echo "文件个数为".count($arr)-2."个";
//这里要减去2
php 查询文件夹内有多少个文件夹php查询文件夹内的文件个数:
//获取目录/文件列表
public function getDirFile( $Dir ){
if( is_dir($Dir) ){
$DirFileArray['DirList'] = $this->getDir( $Dir );
if( $DirFileArray ){
foreach( $DirFileArray['DirList'] as $Handle ){
$File = $Dir.DS.$Handle;
$DirFileArray['FileList'][$Handle] = $this->getFile( $File );
}
}
}else{
$DirFileArray[] = '[Path]:\''.$Dir.'\' is not a dir or not found!';
}
return $DirFileArray;
}
}
?>
关于php获取文件个数的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php获取文件个数 php获取文件夹文件数目的详细内容...