问题
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:
__FILE__
is a magic constant, therefore you cannot wrap it in quotes:$folder = dirname(__FILE__)."/../images/*";
You missed a
$
infiles
:$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