Jump to content

[SOLVED] rotating a series of images from an image directory


fgoldberg

Recommended Posts

I have a jpeg image on my home page and I'm trying to replace it with a series of images that will rotate whenever the page is refeshed.  I'm using the php code from this site:

 

http://alistapart.com/articles/randomizer/

 

According to this article, you load a php file named rotate.php into the directory with your images and then you replace your image source url with the url for the rotate.php file.

 

I've loaded rotate.php into a subdirectory calleded /images/homeimages/ along with several jpeg files.

 

I'm using the following code in my test file (http://petiteresource.com/index-test.php):

 

<img class="homephoto" src="images/homeimages/rotate.php"

alt="Petite Celebrity Photo " title="Petite Celebrity Photo"/>

 

All I'm getting is the missing image file icon (red x in a little box) and the title of the image. 

 

Can you help?

 

I'm very new at this and hardly know anything about php, so please keep that in mind.  Thanks!

 

Here's a script i made that i have saved

 

 

 

 

 

                $path = '/path/to/imagefolder/';

$dir = opendir($path) or die('--[ could not open directory for main image selection. ]--');

$images = array();

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

if ( ($file != 'Thumbs.db') && ($file != '.') && ($file != '..') && ($file != '') && ($file != ' ') ) {

// insert $file into the end of the array.

array_push($images, $file);

}

}

shuffle($images); // shuffle the array

$image = $images[0]; // pick first element in array

}

echo '<img src=" . $path . $image . " />';

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.