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
https://forums.phpfreaks.com/topic/74691-random-image-gen-help/
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
https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-378159
Share on other sites

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.