OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 11:38 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Random avatar...
PostPosted: Tue Apr 30, 2002 7:28 pm 
Whooppeee, I figured out how to have random avatars. Refresh this page and watch my avatar, a different one can appear at random. There is 8 avatars in all. :)


Top
  
 
 Post subject: Re:Random avatar...
PostPosted: Wed May 01, 2002 12:25 am 
Kewl.

Is this done with PHP?

K.J.


Top
  
 
 Post subject: Re:Random avatar...
PostPosted: Wed May 01, 2002 1:23 pm 
Yeah, I still need to refine it, so the randomizer will work better... but here is the source:

Code:
<?php
$avatars = array("0","1","2","3","4","5","6","7");
$random = array_rand ($avatars, 1);
$directory = "http://www.agigames.com/avatar";

if ($random == "0") {
  $avataropen = "$directory/agi.gif";
}
if ($random == "1") {
  $avataropen = "$directory/death.gif";
}
if ($random == "2") {
  $avataropen = "$directory/blue.gif";
}
if ($random == "3") {
  $avataropen = "$directory/idiot.gif";
}
if ($random == "4") {
  $avataropen = "$directory/idiot2.gif";
}
if ($random == "5") {
  $avataropen = "$directory/skull.gif";
}
if ($random == "6") {
  $avataropen = "$directory/stupid.gif";
}
if ($random == "7") {
  $avataropen = "$directory/homer.gif";
}
if ($random > "7") {
  $avataropen = "http://www.agigames.com/avatar.gif";
}

$avatar = fopen("$avataropen", "w+");

while (!feof ($avatar)) {
  print fread($avatar,120);
}
?>


Top
  
 
 Post subject: Re:Random avatar...
PostPosted: Mon May 06, 2002 4:20 am 
Well I have finshed the avatar uploader completely. It checks a directory at http://www.agigames.com/avatar/avatars/ and adds all the avatars that are in the directory to the random array. Then it picks one out of the array and displays it.

I don't have to name the avatars anymore in my source code, all I do is upload more avatar when I want them to appear.

Code:
<?
$absolute_path = "/home/agigames/public_html/avatar/avatars";
$directory = "http://www.agigames.com/avatar/avatars";
$dir = opendir($absolute_path);
while($avatar = readdir($dir)) {
  if (($avatar != "..") and ($avatar != ".")) {
    $avatars[] = "$avatar";
  }
}
$random = array_rand ($avatars, 1);
$randomAvatarURL=$avatars[$random];
$avatar = fopen("$directory/$randomAvatarURL", "w+");
while (!feof ($avatar)) {
  print fread($avatar,120);
}
?>


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 133 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group