...

View Full Version : Show random Image



SDP2006
10-11-2003, 06:25 PM
I have an array of images


<?php
Images[0] = "images/img1.gif";
Images[1] = "images/img2.gif";
Images[2] = "images/img3.gif";
Images[3] = "images/img4.gif";
?>

How can I make it to where the script will show a random image?

Thanks

Nightfire
10-11-2003, 06:44 PM
http://php.net/rand

Íkii
10-11-2003, 08:05 PM
chdir('images');
header('Content-type: image/gif');
readfile(array_rand(glob('*.gif')));

well 4.3 or so and above would probably manage something along those lines

As nightfire mentioned, check the rand and array_rand functions in the manual

SDP2006
10-12-2003, 03:10 AM
so


<?php
Images[0] = "images/img1.gif";
Images[1] = "images/img2.gif";
Images[2] = "images/img3.gif";
Images[3] = "images/img4.gif";
rand(0,3);
?>

???

Thanks

Nightfire
10-12-2003, 04:53 AM
Try it

SDP2006
10-12-2003, 08:20 PM
Nope, doesn't work! Get all kinds of rancid errors



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum