Ciao a tutti, è il mio primo post qui!
Ho questo codice per mostrare immagini random.
Avrei bisogno che lo script trovasse anche le immagini nelle subdirectory all'infinito, cioè quando la cartella è impostata su banner/2 dovrebbe anche leggere banner/2/bis e banner/2/bis/ter.
Non ho idea di come fare.
Qualcuno riesce ad aiutarmi?
codice:
<?php
/*
You can also specify the image to display like this:
Set $folder to the full path to the location of your images.
For example: $folder = '/user/me/example.com/images/';
If the rotate.php file will be in the same folder as your
images then you should leave it set to $folder = '.';*/
// random number 1 - 100
$result_random=rand(1, 100);
// if result less than or equal 70, display ad 1 (70%)
if($result_random<=70){
$folder = 'banner/1/';
}
// if result less than or equal 90, display ad 2 (20%)
elseif($result_random<=90){
$folder = 'banner/2/';
}
// if result less than or equal 100, display ad 3 (10%)
elseif($result_random<=100){
$folder = 'banner/2/bis/';
}
// OK
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
// --------------------- END CONFIGURATION -----------------------
$img = null;
if (substr($folder,-1) != '/') {
$folder = $folder.'/';
}
if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
file_exists( $folder.$imageInfo['basename'] )
) {
$img = $folder.$imageInfo['basename'];
}
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
) {
$fileList[] = $file;
}
}
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
}
}
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
}
}
?>