php loop folder get the file names and size

只愿长相守 提交于 2019-12-24 02:12:43

问题


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.

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

回答1:


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. __FILE__ is a magic constant, therefore you cannot wrap it in quotes:

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

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



回答3:


Are you sure

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

is valid? do you mean

dirname(__FILE__)


来源:https://stackoverflow.com/questions/8639622/php-loop-folder-get-the-file-names-and-size

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!