* (pensez à remplacer PATH_TO_THIS_FOLDER par le bon chemin)
*
* @author TyKayn, Baptiste Lemoine
* @filesource http://artlemoine.com
*/
function make_random_pic($path=''){
$files = scandir(getcwd().'/'.$path);//scanne le dossier courant
$formats_ok = array('.jpg','jpeg','.png','.bmp','.gif');
$i=0;
$clean_files = array();
//pour chaque fichier, si c'est une image l'ajouter au tableau des random a choisir
foreach ($files AS $k=>$v){
$format = substr(strtolower($v),-4,4);
if(in_array($format,$formats_ok)){
$clean_files[$i]=$v;
$i++;
}
}
//choisit une image au hasard
if(count($clean_files)>0){
$random_number = rand(0, count($clean_files)-1);
$addr = $path.$clean_files[$random_number];
//écit le code HTML pour afficher l'image
echo"
";
}
else{
echo" (pas d'image dans ce dossier)";
}
}
?>