► Afficher le texte
Créé un fichier nommé : rotate.php :
Dans la page ou afficher l'image :
Code : Tout sélectionner
<?php
/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank. ex : $folder = 'images/';
$folder = '';
// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along
header('Location: '.$folder.$files[$rand]); // Voila!
?>
Code : Tout sélectionner
<img src="/test/rotate.php" alt="A Random Image" />
2°) Afficher les image d'un repertoire dans un tableau :
► Afficher le texte
Code : Tout sélectionner
<?php
/******************************************************************************/
/* */
/* __ ____ */
/* ___ / / ___ / __/__ __ _____________ ___ */
/* / _ \/ _ \/ _ \_\ \/ _ \/ // / __/ __/ -_|_-< */
/* / .__/_//_/ .__/___/\___/\_,_/_/ \__/\__/___/ */
/* /_/ /_/ */
/* */
/* */
/******************************************************************************/
/* */
/* Titre : Visionneuse */
/* */
/* URL : http://www.phpsources.org/scripts39-PHP.htm */
/* Auteur : Mathieu */
/* Date édition : 02 Sept 2004 */
/* */
/******************************************************************************/
//affichage de l'entête du tableau
echo
"
<table border=1 align=center>
<tr>
<td>Image</td>
<td>Nom de l'image</td>
</tr>
";
//nom du répertoire contenant les images à afficher. ex : $nom_repertoire = 'images/';
$nom_repertoire = './';
//ouvre le repertoire
$pointeur = opendir($nom_repertoire);
$i = 0;
//stocke les noms de fichiers images dans un tableau
while ($fichier = readdir($pointeur)) {
if (substr($fichier, -3) == "gif" ||
substr($fichier, -3) == "jpg" ||
substr($fichier, -3) == "png" ||
substr($fichier, -4) == "jpeg" ||
substr($fichier, -3) == "PNG" ||
substr($fichier, -3) == "GIF" ||
substr($fichier, -3) == "JPG")
{
$tab_image[$i] = $fichier;
$i++;
}
}
//on ferme le répertoire
closedir($pointeur);
//on trie le tableau par ordre alphabétique
array_multisort($tab_image, SORT_ASC);
//affichage des images (en 60 * 60 ici)
for ($j=0;$j<=$i-1;$j++)
{
$image = '<img src="'.$nom_repertoire.'/'.$tab_image[$j].'" width="60" height="60">';
// affichage bas du tableau
echo
'
<tr>
<td align="center">'.$image.'</td>
<td align="center">'.$tab_image[$j].'</td>
</tr>
';
}
echo '</table>';
?>