PDA

View Full Version : Random images generator


SharronH
10-18-2003, 05:40 AM
OK guys.... I need some help finishing this code. What I wanted to do is to put a [img]http:///www.forumxxx.com/forum/image.php[/img.] in the signature field and have it randomly show a sig in the "images" folder. I have like 8 different sigs and I want it to randomly show one each time a page is refreshed.

Here's the php file. It works great when you call it on IE but when I put the img code in the signature profile, it won't show it on the thread. Any help please?

require("./global.php");
$dir=opendir("/home/example/public_html/forum/images/");
//This is the directory route to the folder
$directory="images/";
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on

$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir)
{
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s)
{
if(ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);

//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "<br><img src=\"$directory$image[$randNum]\" $size[3]>";
?>

SharronH
10-19-2003, 01:06 AM
Anyone? I know the .php will generate pic if the dynamic URL is enabled in your forum, which mine is.

For example, when you attach a pic to your forum, the URL to the pic will be http://www.yourforum.com/forums/attachment.php?s=&postid=97094. If you use the [img][img.] code, then it'll show the picture..... but in my code, it'd only show the picture in IE but not in vB. I know I might sound confusing, but I'd be more than happy to answer any questions to any1 that's confused. TIA