fgoldberg Posted December 15, 2007 Share Posted December 15, 2007 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! Quote Link to comment Share on other sites More sharing options...
play_ Posted December 15, 2007 Share Posted December 15, 2007 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 . " />'; Quote Link to comment Share on other sites More sharing options...
fgoldberg Posted December 16, 2007 Author Share Posted December 16, 2007 Thanks! I tried it and it works perfectly! Quote Link to comment Share on other sites More sharing options...
play_ Posted December 17, 2007 Share Posted December 17, 2007 don't forget to click topic solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.