I have pictures in my folder: 1.jpg, 2.jpg, 3.jpg ...

I need to know the "maximum name of the picture", what would the next call max + 1 .

I have this: =)

$d=opendir("."); while($name = readdir($d)){ if($name=="." or $name=="..") { continue; } echo $name."<br>"; } 

    2 answers 2

     $max = 0; $d=opendir("."); while($name = readdir($d)){ if($name=="." or $name=="..") { continue; } $num = basename($name,'.jpg'); if ($max < $num) $max=$num; } echo $max; 
    • Thank you very much! everything is working. - JL
     $files = glob("*.jpg"); sort($files, SORT_NUMERIC); $max = (int)basename(array_pop($files), ".jpg");