First of all apologies for the vague question title. I couldn't come up with a title that made sense.
I'm looping through image files in a directory using:
$folder = 'frames/*';
foreach(glob($folder) as $file)
{
}
The Requirement
I want to measure each file's size and if it's size is less then 8kb
, move to the next file and check it's size and do so until you get the file whose size is greater than 8kb
. Right now I'm using
$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
I had a look at next()
and current()
but couldn't come up with a solution that I was looking for.
So for a result like this:
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
UPDATE
The complete code that I'm using
$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
}
}