Mammouth du PHP |
859 Messages
26 avr. 2005, 16:08
Là où tu as de la chance c'est que j'avais besoin de développer un script pour afficher l'image aléatoire d'un dossier et je viens de le finir :
<?php
$chem_img = "./images";
$handle = opendir($chem_img);
while ($file = readdir($handle))
{
if($file != '..' && $file !='.')
{
if (!is_dir($chem_img."/".$file))
{
$listef[] = $file;
}
}
}
$random_img = rand(0, count($listef));
$size = getimagesize($chem_img."/".$listef[$random_img]);
$largeur_maxi = 180;
if ($size[0] > $largeur_maxi)
{
$width = $largeur_maxi;
$theight = ($size[0]/$largeur_maxi);
$height = ($size[1]/$theight);
}
else
{
$width = $size[0]; $height = $size[1];
}
echo "<a href=\"".$chem_img."/".$listef[$random_img]."\" onclick=\"window.open(this.href,'_blank');return false;\"><img style=\"border: none; width: ".$width."px; height: ".$height."px\" src=\"".$chem_img."/".$listef[$random_img]."\" alt=\"".$listef[$random_img]."\" /></a>";
closedir($handle);
?>
Si ça ne marche pas tu ne t'en prends qu'à toi car il marche très bien

Modifié en dernier par
flitox le 26 avr. 2005, 19:08, modifié 1 fois.