View Single Post
Old 12-30-2012, 05:50 AM  
seeandsee
Check SIG!
 
seeandsee's Avatar
 
Industry Role:
Join Date: Mar 2006
Location: Europe (Skype: gojkoas)
Posts: 50,945
Quote:
Originally Posted by Oracle Porn View Post
Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:
<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files     = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}
Hi, thanks for this code. Can you point me to some good php tutorial site, i have experience in programing (c, c++, basic, even pascal) but i need good site to learn some step by step php code?
__________________
BUY MY SIG - 50$/Year

Contact here

Last edited by seeandsee; 12-30-2012 at 05:51 AM..
seeandsee is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote