Random avatar...
Posted: 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.
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);
}
?>
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);
}
?>