Une petite fonction fait maison.
function CountImgPath($path)
{
/*
compte les images JPG PNG GIF dans les dossiers
structure:
Dossier_maitre:
|_dossier1:
|_image1.jpg
|_image2.gif
|_image3.png
|_dossier2:
|_image1.jpg
|_image2.gif
|_image3.png
|_dossier3:
|_image1.jpg
|_image2.gif
|_image3.png
|_dossier4:
|_image1.jpg
|_image2.gif
|_image3.png
TOTAL: 12
Peut servir également pour afficher les dossier ou les images.
*/
$count=0;
$compteur = count(glob($path."/{*.gif,*.jpg,*.png}", GLOB_BRACE));
$count = $compteur + $count;
//echo $path.' - '.$compteur.'<br/>'; //affiche le dossier
//compte les images dans les dossier recursif
if ($path[strlen($path)-1] != "/")$path .= "/";
if (is_dir($path))
{
$d = opendir($path);
$iCpt1 = substr_count ($path,'/thumbs' ); //sauf dans ce dossier.
if($iCpt1==0)
{
while ($f = readdir($d))
{
if ($f != "." && $f != "..")
{
$rf = $path . $f; // chemin relatif au fichier php
$iCpt2 = substr_count ($rf,'/thumbs' );
if (is_dir($rf)and($iCpt2==0))
{
$compteur = count(glob($rf."/{*.gif,*.jpg,*.png}", GLOB_BRACE));
$count = $compteur + $count;
//echo $rf.' - '.$compteur.'<br/>'; //affiche le dossier
}
}
}
}
closedir($d);
}
return $count;
}
appel:
$path = $_SERVER['DOCUMENT_ROOT']."/userfiles/idmember/album/";
if(is_dir($path))
{
echo CountImgPath($path);
}