まず、あいまいな質問のタイトルについてお詫び申し上げます。意味のあるタイトルが思いつきませんでした。
次を使用して、ディレクトリ内の画像ファイルをループしています。
$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
}
}