1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| /*
+----------------+
| Configuration |
+----------------+
*/
$imgpath = "img/vignette/"; // chemins des images
$textalter = "image aleatoire"; // texte alternative de l'image (attribut alt)
/*
+--------------+
| Programme |
+--------------+
*/
$nodir = 0;
if ($imgpath == ".." || $imgpath == "." || $imgpath == "")
{
$nodir = 1;
$imgpath = ".";
}
$j = strlen($imgpath);
$j--;
if ($imgpath[$j] != '/' && $imgpath != ".")
$imgpath .= '/';
if (is_dir($imgpath))
{
if ($condir = opendir($imgpath))
{
$i = 0;
while (($curfile = readdir($condir)) != false)
{
$extension = "";
$extension = preg_replace("/.+\.(.{3,4})/", "$1", $curfile);
if ($extension == "png" || $extension == "gif" || $extension == "bmp" || $extension == "jpg" || $extension == "jpeg")
{
$i++;
}
}
if ($images{1} == "")
{
echo "Aucunes images dans le dossier !";
}
else
{
$i = rand(1, $i);
$image = strtr($images{$i},'éèê','eee');
$name=substr($image,0,-4);
$size=getimagesize($imgpath.$image);
if ($size[1]>170){
echo "<img src=\"";
if ($nodir != 1)
echo $imgpath;
echo "".$image."\" alt=\"".$textalter."\" height=\"165\"/><br>";
echo "<span style=\"font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#FFFFFF; font-weight:500 \">".$name."</span>";
}else{
echo "<img src=\"";
if ($nodir != 1)
echo $imgpath;
echo "".$image."\" alt=\"".$textalter."\"/><br>";
echo "<span style=\"font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#FFFFFF; font-weight:500 \">".$name."</span>";
}
}
}
else
{
echo "Impossible d'ouvrir le dossier d'image !";
}
}
else
{
echo "Le répertoire d'images spécifié est incorrect !";
}
?> |
Partager