Jump to content

Random Image Gen HELP!


butler68

Recommended Posts

I'm trying to get the image on my home page to change everytime it is visited. http://www.butler-motors.com

I have the images located at http://www.butler-motors.com/images/home/main

 

I have tried this with 6 different codes I have found on the net. Everytime I just get a broken image and never displays a picture. Is there something else I need to do other than adding in the PHP code. For example, are all websites setup to run PHP or is there something I need to setup before? Thank you for your help.

Link to comment
Share on other sites

i place this script in my image directory, it simply displays a random image:

<?php
$files = array(); $i = -1; // Initialize some variables
$handle = opendir('./');
while (false !== ($file = readdir($handle))) {
if (preg_match('/\.'.'jpg'.'$/i', $file, $test)) { // faster than ereg, case insensitive
	$files[] = $file; // it's good
	++$i;
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along
header('Location: '.$folder.$files[$rand]); // Voila!
?>

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.