baptizer
07-13-2004, 11:13 AM
Hello All!
I am hoping someone can help me. I know there are a few other 'display random image' codes floating around, however, I would like to get this one to work. The difference between this code and the other code floating around? Well, this code does not require you to number your images 1,2,3,4,5,etc. It adds the images to an array regardless of their name.
I have this code working on my HTML frontpage (not related to vb at all) and I would like to get it to work with my vbadvance homepage. Basically I am trying to make www.2darkpark.com/vbulletin/2dp.php look like www.2darkpark.com (the random display imager is in the top right corner). Can anyone help me with this code? I dont know which template to add it too! here is the code:
<?php
$DIRNAME = "./images/"; #The path RELATIVE to this script to the dir containing the images.
#The value should end with a "/" character!
#This directory should contain ONLY images.
######## NOTHING BELOW THIS LINE SHOULD NEED TO BE CONFIGURED!!! ########
$images = array(); #Holds the list of images to choose randomly from.
$file_handle=opendir($DIRNAME);
$x = 0;
while ($file = readdir($file_handle)) {
if($file == '.' || $file == '..') { continue; }
if(is_dir($DIRNAME.$file)) { continue; }
$images[$x] = $DIRNAME . $file;
$x += 1;
}
closedir($file_handle);
function DisplayRandomImage() {
global $images;
if (count($images) > 0) {
srand((double)microtime()*1000000);
$rnd_img = rand(0,(count($images) - 1));
return $rnd_img;
}
}
?>
This is the call that I use in my HTML website front page:
<table width="175" border="0" cellspacing="0" cellpadding="0" height="67">
<tr>
<td width="175">
<div align="center"><a href="http://www.2darkpark.com/"><IMG SRC="<?=$images[DisplayRandomImage()];?>" ALT="" border="0"></a></div>
</td>
</tr>
</table>
It works perfectly on the HTML page, just cant get it to work on the vbadvanced page :(
I am hoping someone can help me. I know there are a few other 'display random image' codes floating around, however, I would like to get this one to work. The difference between this code and the other code floating around? Well, this code does not require you to number your images 1,2,3,4,5,etc. It adds the images to an array regardless of their name.
I have this code working on my HTML frontpage (not related to vb at all) and I would like to get it to work with my vbadvance homepage. Basically I am trying to make www.2darkpark.com/vbulletin/2dp.php look like www.2darkpark.com (the random display imager is in the top right corner). Can anyone help me with this code? I dont know which template to add it too! here is the code:
<?php
$DIRNAME = "./images/"; #The path RELATIVE to this script to the dir containing the images.
#The value should end with a "/" character!
#This directory should contain ONLY images.
######## NOTHING BELOW THIS LINE SHOULD NEED TO BE CONFIGURED!!! ########
$images = array(); #Holds the list of images to choose randomly from.
$file_handle=opendir($DIRNAME);
$x = 0;
while ($file = readdir($file_handle)) {
if($file == '.' || $file == '..') { continue; }
if(is_dir($DIRNAME.$file)) { continue; }
$images[$x] = $DIRNAME . $file;
$x += 1;
}
closedir($file_handle);
function DisplayRandomImage() {
global $images;
if (count($images) > 0) {
srand((double)microtime()*1000000);
$rnd_img = rand(0,(count($images) - 1));
return $rnd_img;
}
}
?>
This is the call that I use in my HTML website front page:
<table width="175" border="0" cellspacing="0" cellpadding="0" height="67">
<tr>
<td width="175">
<div align="center"><a href="http://www.2darkpark.com/"><IMG SRC="<?=$images[DisplayRandomImage()];?>" ALT="" border="0"></a></div>
</td>
</tr>
</table>
It works perfectly on the HTML page, just cant get it to work on the vbadvanced page :(