Display Random Image from a Folder

  • 13 years ago
    Hey guys/gals,

    In all the programming I've done, I have strayed from Internet coding as much as possible... but now I am in need of a simple script.  Short story is I have helped a friend setup a forum based web site with a news page to the forum.  What I would like to do is have an opening image that is a random selection from all the available images placed in a folder.  So I need a php script that would do the following(I will increment MaxImage each time I add a new artwork submission):

    intRandom = Int((Rnd * MaxImage) + 1)
    Select Case intRandom
         Case 1
              Display /path/to/image1.jpg link to news.php
         Case 2
              Display /path/to/image2.jpg link to news.php
    .
    .
    .
    End Select

    Assuming the link would be resolved by using href.  Any help would be greatly appreciated.
















  • 13 years ago

    why cant you try it like this,
    organize image names like image_1.jpg,image_2.jpg,......,image_20.jpg

    then pick up a ramdom number form 1 to 20 and store it in $randNo.

    <image src="<?php echo"images/artwork/image_". $randNo.".jpg" ?> />




    hope this is useful for you

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are 10 types of people in the world, those who can read binary, and those who can't.”