Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random images?
Index -> Graphics and Design, Web Design -> (X)HTML Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Corybu




PostPosted: Sat Oct 04, 2003 4:57 pm   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Blade




PostPosted: Sat Oct 04, 2003 5:09 pm   Post subject: (No subject)

well... you'd have to use some sort of scripting language... ie: perl, php etc.
Corybu




PostPosted: Sat Oct 04, 2003 5:10 pm   Post subject: (No subject)

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




PostPosted: Sat Oct 04, 2003 5:14 pm   Post subject: (No subject)

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




PostPosted: Sat Oct 04, 2003 5:15 pm   Post subject: (No subject)

Lol... I dont get it. Do all that stuff with html? or another script?

Ive never done any scripting...
Amailer




PostPosted: Sat Oct 04, 2003 5:24 pm   Post subject: (No subject)

PHP:
code:

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




PostPosted: Sat Oct 04, 2003 5:26 pm   Post subject: (No subject)

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




PostPosted: Sat Oct 04, 2003 5:27 pm   Post subject: (No subject)

Which one you are talking about?
Sponsor
Sponsor
Sponsor
sponsor
Corybu




PostPosted: Sat Oct 04, 2003 5:27 pm   Post subject: (No subject)

the php script
Amailer




PostPosted: Sat Oct 04, 2003 5:30 pm   Post subject: (No subject)

1: you need php installed,
create a .php file (i.e: randomeimg.php )
put the script in, and add afer that

code:

$dir="./where the/images/are/";
getRandomImage($dir);
Blade




PostPosted: Sat Oct 04, 2003 5:31 pm   Post subject: (No subject)

code:
<?
$dir = "images/";
$i = 0;
if ($handle = opendir($dir)) {
  while (false !==($file[$i] = readdir($handle))){
    $i++;
  }
}
$img = $dir . $file[rand(2,$i - 1)];
echo "<img src=$img>";
?>


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




PostPosted: Sat Oct 04, 2003 5:31 pm   Post subject: (No subject)

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




PostPosted: Sat Oct 04, 2003 5:33 pm   Post subject: (No subject)

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




PostPosted: Sat Oct 04, 2003 5:35 pm   Post subject: (No subject)

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. Smile
Amailer




PostPosted: Sat Oct 04, 2003 5:36 pm   Post subject: (No subject)

better if you use the JAVASCRIPT ONE, cuz you don't have PHP
Display posts from previous:   
   Index -> Graphics and Design, Web Design -> (X)HTML Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: