Need a PHP script

Woraug

New Member
Messages
18
Reaction score
0
Points
0
I'm looking for a PHP script that I had a while back, and now don't remember. What it did, every time you refreshed a page, it was a different banner. As seen here:

http://www.katbox.net/laslindas/

Anyone know how to do this?
 

Torch

New Member
Messages
634
Reaction score
0
Points
0
Woraug said:
I'm looking for a PHP script that I had a while back, and now don't remember. What it did, every time you refreshed a page, it was a different banner. As seen here:

http://www.katbox.net/laslindas/

Anyone know how to do this?
Like this ;) (the script gets all images from folder it is in and randomly displays one of them):
PHP:
<?
if ($dir = opendir(".")) 
{ 
     $list = buildimagearray($dir); 
     displayrandomimage($list); 
} 
 
function buildimagearray($dir) 
{ 
     while (false !== ($file = readdir($dir))) 
     { 
          if (!is_dir($file) && getimagesize($file)) 
          { 
               $list[] = $file; 
          } 
     } 
     array_shift($list);
     return $list; 
} 
 
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; 
     } 
} 
?>
 

Woraug

New Member
Messages
18
Reaction score
0
Points
0
How would I get it to read from a specific directory, instead of the one the script in put in?
 

swirly

Active Member
Messages
1,930
Reaction score
0
Points
36
Code:
<?
if ($dir = opendir(".")) 
{ 
     $list = buildimagearray($dir); 
     displayrandomimage($list); 
}
i beleive u just change the opendir code...make it
Code:
<?
if ($dir = opendir("blah/blahblah")) 
{ 
     $list = buildimagearray($dir); 
     displayrandomimage($list); 
}
 
Last edited:

Woraug

New Member
Messages
18
Reaction score
0
Points
0
Very cool. One final question (which I didn't think to ask before) How would I implement this into my forum? I'm not sure what I would edit to make this work. Invision v1.3.1

(BTW, thanks much for the help so far guys, you rock! :biggthump)
 

Torch

New Member
Messages
634
Reaction score
0
Points
0
You just have to use this where ever you want your images to show:

Code:
<img src="path/to/dir/where/script/is/script.php" border="0" />
 

Woraug

New Member
Messages
18
Reaction score
0
Points
0
Right on! You guys have reached previously unheard of levels of badass.
 
Top