php loop文件夹获取文件名和大小

时间:2022-09-01 23:24:58

I want make a loop of my fold, get all the files and make a judge, print all the files name witch size are less than 10kb. But I get nothing from this code (no php error hint, just 0 result, and I am sure there has 10 files at lest < 10kb), where is the problem? Thanks.

我想制作一个我的折叠循环,获取所有文件并做出判断,打印所有文件名称女巫大小小于10kb。但是我从这段代码中得不到任何东西(没有php错误提示,只有0个结果,我确信有10个文件至少<10kb),问题出在哪里?谢谢。

$folder = dirname('__FILE__')."/../images/*";
foreach(glob($folder) as files){
 $size = filesize(files);
 if($size<10240){
  echo files.'<br />';
 }
}

3 个解决方案

#1


3  

I think there's a typo, because

我认为这是一个错字,因为

dirname('__FILE__')

should be (without quotes)

应该(没有引号)

dirname(__FILE__)

and also, your variable files doesn't have a dollar sign

而且,您的变量文件没有美元符号

$size = filesize($files);

and also here echo $files

还有回声$文件

That's it, it should fix your problem

就是这样,它应该解决你的问题

#2


1  

  1. __FILE__ is a magic constant, therefore you cannot wrap it in quotes:

    __FILE__是一个魔术常量,因此你不能用引号括起来:

    $folder = dirname(__FILE__)."/../images/*";
    
  2. You missed a $ in files:

    你错过了一个$ in文件:

    $size = filesize($files);
    // and
    echo $files.'<br />';
    

#3


0  

Are you sure

你确定

$folder = dirname('__FILE__')."/../images/*";

is valid? do you mean

已验证?你的意思是

dirname(__FILE__)

#1


3  

I think there's a typo, because

我认为这是一个错字,因为

dirname('__FILE__')

should be (without quotes)

应该(没有引号)

dirname(__FILE__)

and also, your variable files doesn't have a dollar sign

而且,您的变量文件没有美元符号

$size = filesize($files);

and also here echo $files

还有回声$文件

That's it, it should fix your problem

就是这样,它应该解决你的问题

#2


1  

  1. __FILE__ is a magic constant, therefore you cannot wrap it in quotes:

    __FILE__是一个魔术常量,因此你不能用引号括起来:

    $folder = dirname(__FILE__)."/../images/*";
    
  2. You missed a $ in files:

    你错过了一个$ in文件:

    $size = filesize($files);
    // and
    echo $files.'<br />';
    

#3


0  

Are you sure

你确定

$folder = dirname('__FILE__')."/../images/*";

is valid? do you mean

已验证?你的意思是

dirname(__FILE__)