<?php
$imgfolder = "images/mini";
// Checks if the file is an image. If not, it won't be added to the image list
function is_image($filename){
$filename = strtolower($filename) ;
$ext = split("[/\.]", $filename) ;
$n = count($ext)-1;
$ext = $ext[$n];
// Here you can list the extensions you want to be allowed
if($ext == "jpg" || $ext == "JPG" || $ext == "jpeg" || $ext == "JPEG" || $ext == "gif" || $ext == "GIF" || $ext == "png" || $ext == "PNG") {
return true;
} else {
return false;
}
}
// Read the image folder into an array
$dir = opendir($imgfolder);
$array = array();
// Run through the folder
while($file = readdir($dir)) {
// Checks if the file is an image. Check the is_image() function a but up in this file
if(is_image($file)) {
// It's an image!! Put it into the array
array_push($array, $file);
}
}
// Count the amount of images in the array
$count = (count($array)-1);
// Generate a random number
$rand = rand(0,$count);
// Select an image from the array based on the random number
$img = $array[$rand];
// Output the image
echo '<img src="'.$imgfolder.'/'.$img.'" border="1">';
?>
kaynak: ordan burdan
Tags: altın, nasıl, nedir, php, resim, scripti, ScriptlerPhp - Klasör Altındak Resimlerden Rastgele Göstermek (scripti, nasıl, nedir?) konusu
Benzer yazılar:
- Benzer yazı yok