Try this bit of code and see if it works.  (I don't know if there's a less
taxing (on the server) way to get a count of files in a directory or not.)

$myDirectory = dir("yourdirectory");
while($entry=$myDirectory->read()) 
{
    $filecount++;
}
$myDirectory->close();

$number = rand(1, $filecount); 
$file = $number . "." . "gif";
 
echo"<img src = 'random_images/$file'>";


Josh Hoover
KnowledgeStorm, Inc.

Searching for a new IT solution for your company? Need to improve your
product marketing? 
Visit KnowledgeStorm at www.knowledgestorm.com to learn how we can simplify
the process for you.
KnowledgeStorm - Your IT Search Starts Here
      

> I have a web page that displays an image.  I would like to randomize
> which image it displays when the page loads.  Every possible 
> image will
> be the same dimensions and file format.  Each image will be named a
> consecutive number begining with 1.
> 
> The code I am using is:
> 
> $number = rand(1, 10);
> 
> $file = $number . "." . "gif";
> 
> echo"<img src = 'random_images/$file'>";
> 
> I'm wondering if there is a way to count how many files are in the
> random_images directory, so I can dynamically set the range of my
> rand().  This way I can add images to the random_images directory
> without having to increase the range in the php code.
> 
> Thanks!
> 
> Nick

Reply via email to