
-----------------------------------
Corybu
Sat Oct 04, 2003 4:57 pm

Random images?
-----------------------------------
Anyone know how to display random images?

Ive got a website that I need to make for a friends band, and I have various logos that i'd like to place in a frame in the top left corner. 

If anyone could tell me how this os done, or point me to t autorial for it, or give me a code/script for it, Id be very grateful. 

Thanking you all in advance,

Cory.

-----------------------------------
Blade
Sat Oct 04, 2003 5:09 pm


-----------------------------------
well... you'd have to use some sort of scripting language... ie: perl, php etc.

-----------------------------------
Corybu
Sat Oct 04, 2003 5:10 pm


-----------------------------------
I dont know either of those....

Could you or someone here help me out with this one?

I was hoping there was an html way...

-----------------------------------
Blade
Sat Oct 04, 2003 5:14 pm


-----------------------------------
no... html is pretty much tags that format text, it cant caculate anything
well... i'd read the images from a folder into an array, then use a random integer in the array element from 1 to the amount of pictures in the array, then use html to present it...

-----------------------------------
Corybu
Sat Oct 04, 2003 5:15 pm


-----------------------------------
Lol... I dont get it. Do all that stuff with html? or another script?

Ive never done any scripting...

-----------------------------------
Amailer
Sat Oct 04, 2003 5:24 pm


-----------------------------------
PHP:

function getRandomImage($dir,$type="random")
{ 
global $errors,$seed;

  if (is_dir($dir)) {  

  $fd = opendir($dir);  
  $images = array(); 

      while (($part = @readdir($fd)) == true) {  

          if ( eregi("(gif|jpg|png|jpeg|bmp)$",$part) ) {
              $images[] = $part; 
          } 
      } 

    // adding this in case you want to return the image array
    if ($type == 'all') return $images;

    if ($seed !== true) {
      mt_srand ((double) microtime() * 1000000);
      $seed = true;
    }
      
      $key = mt_rand (0,sizeof($images)-1); 

    return $dir . $images[$key]; 

  } else { 
      $errors[] = $dir.' is not a directory'; 
      return false; 
  } 
} 




Javascript:
http://javascript.internet.com/bgeffects/r-images.html
http://www.google.ca/search?hl=en&ie=UTF-8&oe=UTF-8&q=Javascript%3A+random+images+script&btnG=Google+Search&meta=

-----------------------------------
Corybu
Sat Oct 04, 2003 5:26 pm


-----------------------------------
So, with that, I just put it on the html page where I want it to appear, and put the pics in a directory all by themselves?

-----------------------------------
Amailer
Sat Oct 04, 2003 5:27 pm


-----------------------------------
Which one you are talking about?

-----------------------------------
Corybu
Sat Oct 04, 2003 5:27 pm


-----------------------------------
the php script

-----------------------------------
Amailer
Sat Oct 04, 2003 5:30 pm


-----------------------------------
1: you need php installed,
create a .php file (i.e: randomeimg.php )
put the script in, and add afer that


$dir="./where the/images/are/";
getRandomImage($dir);


-----------------------------------
Blade
Sat Oct 04, 2003 5:31 pm


-----------------------------------


what amailer gave you as a function... this is the most simple way you can do it...

its php... you need a server that supports php to use it, and you also need ot name your file .php instead of .htm/.html ... or else the server wont execute it..

you can see it working at http://dblade.sytes.net/new/readdir.php

what it does is it reads the folder /images (which is in my new folder on the server) that is full of images, into an array.. then it gets a random number between 2 (because the first two it reads is . and .. ) and the maximum number of images in the folder, then you use the random number in the array to call a random array element
ie: $arrayname[randomnumber]

-----------------------------------
Corybu
Sat Oct 04, 2003 5:31 pm


-----------------------------------
Im assuming I need some kind of software installed to run PHP then?

This site isnt getting hosted on a private server... its just going on free webhosting... Ill have to see if it can use php...

-----------------------------------
Blade
Sat Oct 04, 2003 5:33 pm


-----------------------------------
umm... the server you're using needs to have php for you to use php...
theres only a couple free server that i know of that have php...
tripod.co.uk and host.sk (which isnt in english)

-----------------------------------
Corybu
Sat Oct 04, 2003 5:35 pm


-----------------------------------
I see... Well, as long as its free, I can probably have the site hosted there... Ill just get redirect service for it.

Thanks for the help guys. :)

-----------------------------------
Amailer
Sat Oct 04, 2003 5:36 pm


-----------------------------------
better if you use the JAVASCRIPT ONE, cuz you don't have PHP

-----------------------------------
Blade
Sat Oct 04, 2003 5:38 pm


-----------------------------------
i never think of javascript cuz its evil....

(not a real fan of java or javascript...)

-----------------------------------
Corybu
Sat Oct 04, 2003 11:32 pm


-----------------------------------
Anyone wanna tell me the Java(script) one?

My boss at work said he would find it and give it to me, but I wont see him till friday at the earliest, I want to have something to show my client (hahaha, feels so cool to call somone that) for monday.

So, any help would roxorz, lol.

-----------------------------------
Amailer
Sat Oct 04, 2003 11:53 pm


-----------------------------------
http://dblade.sytes.net/new/images/frozencavern.jpg
http://dblade.sytes.net/new/images/Gohan-The_Son_of_Goku.jpg
http://dblade.sytes.net/new/images/likwidassassin.jpg

ahh awsome!

-----------------------------------
Corybu
Sat Oct 04, 2003 11:55 pm


-----------------------------------
Is that blades?

(url is dblade.something.somethingelse)

Its nice. 

(note to blade, 666 posts!!! AAHHHHHH!!!!!!  :twisted: ) lol.
