|
Images aléatoires
|
Informations rapides |
|
|
Informations détaillées
|
Description :
Petit script qui permet d'afficher aléatoirement une image d'un dossier qui en contient plusieurs.
Extensions : jpg, jpeg, png, gif, bmp.
Placez le où vous désirez que l'image s'affiche.
Portion de code
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
|
<? /* +----------------+ | Configuration | +----------------+ */ $imgpath = ""; // chemins des images $textalter = "image aleatoire"; // texte alternatif 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", $curfi le); if ($extension == "png" || $extension == "gif" || $exten sion == "bmp" || $extension == "jpeg" || $extension == "jpg") { $i++; $images{$i} = $curfile; } } if ($images{1} == "") { echo "Aucunes images dans le dossier !"; } else { $i = rand(1, $i); $image = $images{$i}; echo "<img src=\""; if ($nodir != 1) echo $imgpath; echo "".$image."\" alt=\"".$textalter."\" />"; } } else { echo "Impossible d'ouvrir le dossier d'image !"; } } else { echo "Le répertoire d'images spécifié est incorrect !"; } ?> |
|
Informations & Services |
 |
|
|
 |
Newsletter
Autre Sources
Tips
|