butler68 Posted October 25, 2007 Share Posted October 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/ Share on other sites More sharing options...
JJohnsenDK Posted October 25, 2007 Share Posted October 25, 2007 first you need to check if you webhost is supporting PHP (most do tho)... second it would be nice to see just one of the script you are using so we can check for errors. Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-377616 Share on other sites More sharing options...
butler68 Posted October 25, 2007 Author Share Posted October 25, 2007 I have not even gotten to the point of posting it on my site. I'm just trying to build it in dreamweaver CS3 at the moment. Here is one site I tried http://www.totallyphp.co.uk/scripts/random_image.htm Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-377619 Share on other sites More sharing options...
tippy_102 Posted October 25, 2007 Share Posted October 25, 2007 php files won't run unless you have php set up on your computer. Try uploading the files to the server where your website is hosted and see if it works properly. Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-378085 Share on other sites More sharing options...
phillips321 Posted October 25, 2007 Share Posted October 25, 2007 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! ?> Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-378159 Share on other sites More sharing options...
butler68 Posted October 26, 2007 Author Share Posted October 26, 2007 THANK YOU. All I needed to do was put it on the server. Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-378364 Share on other sites More sharing options...
darkfreaks Posted October 26, 2007 Share Posted October 26, 2007 dont forget to click topic solved Quote Link to comment https://forums.phpfreaks.com/topic/74691-random-image-gen-help/#findComment-378366 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.