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!

 

Link to comment
Share on other sites

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 . " />';

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.