Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Security - Other
Author Message
xXRaZoRXx
New Member
New Member


Joined: Mar 18, 2005
Posts: 11

PostPosted: Sat Jun 25, 2005 10:55 am Reply with quote

Looking for a code that will load a different image randomly on each refresh. I've seen it before but cant find it. Thanks
 
View user's profile Send private message
VinDSL
Life Cycles Becoming CPU Cycles


Joined: Jul 11, 2004
Posts: 614
Location: Arizona (USA) Admin: NukeCops.com Admin: Disipal Designs Admin: Lenon.com

PostPosted: Sat Jun 25, 2005 11:56 pm Reply with quote

Can you be more specific? You talking about an avatar or what?

_________________
.:: "The further in you go, the bigger it gets!" ::.
.:: Only registered users can see links on this board! Get registered or login! | Only registered users can see links on this board! Get registered or login! ::. 
View user's profile Send private message Visit poster's website ICQ Number
boardmerlin
Hangin' Around


Joined: Jun 27, 2005
Posts: 40
Location: Badger State

PostPosted: Wed Jul 06, 2005 11:39 pm Reply with quote

Code:


<?php


if ($dir = opendir("."))

{

     $list = buildimagearray($dir);

     displayrandomimage($list);

}



// This function reads all the files in the current directory and adds all image files to the array $list[]



function buildimagearray($dir)

{

     while (false !== ($file = readdir($dir)))

     {

          if (!is_dir($file) && getimagesize($file))

          {

               $list[] = $file;

          }

     }

     return $list;

}



// This function selects a random image, determines the mime type, opens the file for reading,

// and then outputs the image



function displayrandomimage($list)

{

     srand ((double) microtime() * 10000000);

     $sig = array_rand ($list);



     $size = getimagesize ($list[$sig]);

     $fp = fopen($list[$sig], "rb");



     if ($size && $fp)

     {

          header("Content-type: {$size['mime']}");

          fpassthru($fp);

          exit;

     }

}

?>


try it, it works on mine, just put the images files you want in that same directory that this file is in. Then try image code pointing to that file.
 
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Security - Other

View next topic
View previous topic
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 vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©