Page 1 of 1

Random Images in PHP

Posted: Sat Jan 04, 2003 10:15 pm
by Ax Slinger
On HostMySig.com, an image hosting website, when you upload an image, the code they give you to link to it is a PHP link like this:

Code: Select all

http://www.hostmysig.com/data/username/image.php
They also have an option to call random images.

Code: Select all

http://www.hostmysig.com/data/username/randomsig.php
My question is, does anyone know how to do this? And if you know how, can type up the code for me? I am not a programmer, and know very little about PHP. I would like to add some random images in the header of a digital photography forum in the same way, and I think this code would do it.

Here's an example of what I would like to do, if I add the Image

Each time you hit refresh, you get a different image.

Thanks for your assistance,

Ax

Posted: Sun Jan 05, 2003 1:10 am
by NoFear
Try this:
******************************
<?

$pictures = array("pic1.gif", "pic2.gif", etc...);

shuffle($pictures);

echo "<img src = \".$pictures[0].\">"

?>

*********************************


This should work nice 'n dandy for ya.
=)

Posted: Fri Feb 28, 2003 3:36 pm
by deadlift
actually it won't work.....
the forum will not recognize it as an image and thus it won't work

Posted: Fri Feb 28, 2003 7:42 pm
by decoy1

Code: Select all

$pictures[shuffle($pictures)];
or

Code: Select all

srand(srand((float)microtime()*1000000)); 
echo $pictures[rand(0, count($pictures)-1)];
The second snippet provided by another member from a similar question posted.

Posted: Sat Mar 01, 2003 2:11 am
by hob_goblin

Posted: Sat Mar 01, 2003 5:59 am
by deadlift
<?
header ("Content-type: image/jpeg");
$piczahl = 0;
$pics = "";
$directory = opendir(".");
while($zaehler = readdir ($directory ))
{
if ($zaehler != "." && $zaehler != ".." && $zaehler != "pics2.php" && $zaehler != "" )
{
$piczahl++;
$pics[$piczahl] = $zaehler;

}
}
closedir ($directory);
$zufall = rand ( 1 , $piczahl);
header ("X-Debug: pics/$pics[$zufall]");
readfile ("pics/$pics[$zufall]");
?>
it'll also work this way sorry for it being german :P set dir to whatever directory you want and you don't have to rename all those pics but only jpg's work