Loans - Loans - Mobile Phones - Mortgage
Randome image [Archive] - Threeboy Forums

PDA

View Full Version : Randome image


DaT
02-03-2004, 11:14 AM
Im looking for a randome image code. Ive seen it on a couple sites, Blinky uses it over at www.blinksworld.com

I have looked through the code but i havent got a clue what im looking for, also i've searched for a tutorial but cant find one. if anyone could give me a hand with this it would be great.

cheers - DaT

brentech
02-03-2004, 11:41 AM
http://www.hotscripts.com/PHP/Scripts_and_Programs/Randomizing/Random_Images/index.html

Liquor_Riss
02-03-2004, 11:42 AM
http://robouk.mchost.com/tuts/tutorial.php?tutorial=random

Loads of sites have the tutorial, its just about knowing what to look for ;)

DaT
02-03-2004, 12:25 PM
cheers guys, also on the subject of looking for things www.google.com doesnt work with me, i always get this CPanel thing come up :?

Liquor_Riss
02-03-2004, 12:32 PM
That happened to my mate a while ago, just wait a few hours or something.

DaT
02-03-2004, 12:49 PM
It has been like it for months :(

Liquor_Riss
02-03-2004, 12:54 PM
Really? Oh, only happened to people I know for a day or something.

DaT
02-04-2004, 02:01 PM
yup :( its a bitch, works with everyone else :?

zubaz
02-04-2004, 07:25 PM
here's the code I used for http://start.neverwake.net

// get random picture from /random folder
$dir = "./".$user[skin]."/random/";
if ($handle = @opendir($dir)) {
$xx=0;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$ranpics[$xx] = $file;
$xx++;
}
}
closedir($handle);
}
$r = explode(" ", microtime());
$rand_key = (round($r[0] * 100)) % sizeof($ranpics);
$file = $ranpics[$rand_key];
$randpictext = "$user[skin]/random/$file";

It takes how many microseconds have passed since the last second, and uses that proportion against how many files there are in the directory and rounds to the nearest integer, choosing that picture. Never liked the rand() functions cause they were never really random.

DaT
02-08-2004, 04:31 AM
Cheers :)

scooter
02-13-2004, 09:38 PM
<?php
/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/

// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = '';

// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';

$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>

For the simplest possible installation, just drop this code in a directory with the images you want to rotate, and call it like you would a normal image, for example:

<img src="/dropbox/2003/rotate/rotate.php" alt="A Random Image" />

This is the one I'm using on my site, thanks to www.photomatt.net

DaT
02-14-2004, 03:28 AM
All good, thanks :)