Page 1 of 1

Random avatar...

Posted: Tue Apr 30, 2002 7:28 pm
by AGI1122
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. :)

Re:Random avatar...

Posted: Wed May 01, 2002 12:25 am
by K.J.
Kewl.

Is this done with PHP?

K.J.

Re:Random avatar...

Posted: Wed May 01, 2002 1:23 pm
by AGI1122
Yeah, I still need to refine it, so the randomizer will work better... but here is the source:

Code: Select all

<?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);
}
?>

Re:Random avatar...

Posted: Mon May 06, 2002 4:20 am
by AGI1122
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: Select all

<?
$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);
}
?>