首先为模糊的问题标题道歉。我想不出一个有意义的标题。
我正在使用以下方法遍历目录中的图像文件:
$folder = 'frames/*';
foreach(glob($folder) as $file)
{
}
要求
我想测量每个文件的大小,如果它的大小小于然后8kb
,移动到下一个文件并检查它的大小,直到你得到大小大于的文件8kb
。现在我正在使用
$size = filesize($file);
if($size<8192) // less than 8kb file
{
// this is where I need to keep moving until I find the first file that is greater than 8kb
// then perform some actions with that file
}
// continue looping again to find another instance of file less than 8kb
我看了看,next()
但current()
无法想出我正在寻找的解决方案。
所以对于这样的结果:
File 1=> 12kb
File 2=> 15kb
File 3=> 7kb // <-- Found a less than 8kb file, check next one
File 4=> 7kb // <-- Again a less than 8kb, check next one
File 5=> 7kb // <-- Damn! a less than 8kb again..move to next
File 6=> 13kb // <-- Aha! capture this file
File 7=> 12kb
File 8=> 14kb
File 9=> 7kb
File 10=> 7kb
File 11=> 17kb // <-- capture this file again
.
.
and so on
更新
我正在使用的完整代码
$folder = 'frames/*';
$prev = false;
foreach(glob($folder) as $file)
{
$size = filesize($file);
if($size<=8192)
{
$prev = true;
}
if($size=>8192 && $prev == true)
{
$prev = false;
echo $file.'<br />'; // wrong files being printed out
}
}