mike12255 Posted February 1, 2009 Share Posted February 1, 2009 I have made some code that chooses a random image and displays it, i have spots for three images and all them apear with that white box that has the X in the top left that means picture not found. I cannot seem to figure out the problem, here is my code: <?php // Change this to the total number of images in the folder $total = "11"; // Change to the type of files to use eg. .jpg or .gif $file_type = ".gif"; // Change to the location of the folder containing the images $image_folder = "images/random"; // You do not need to edit below this line $start = "1"; $random = mt_rand($start, $total); $temp1; if ($temp1 < 1){ $temp1 = $random; } if ($temp1 > 0){ $temp2 = $random; } if ($temp1 > 0 && $temp2 > 0){ $temp3 = $random; } $image_name = $random . $file_type; } randomint($image_name); if(randomint($temp1) == randomint($temp2) || randomint($temp1) == randomint($temp3) || randomint($temp3) == randomint($temp2)){ randomint($image_name); }else{ $img1 = randomint($image_name); } randomint($image_name); if(randomint($temp1) == randomint($temp2) || randomint($temp1) == randomint($temp3) || randomint($temp3) == randomint($temp2)){ randomint($image_name); }else{ $img2 = randomint($image_name); } randomint($image_name); if(randomint($temp1) == randomint($temp2) || randomint($temp1) == randomint($temp3) || randomint($temp3) == randomint($temp2)){ randomint($image_name); }else{ $img3 = randomint($image_name); } ?> Link to comment https://forums.phpfreaks.com/topic/143395-random-image-not-working/ Share on other sites More sharing options...
Lucky_PHP_MAN Posted February 1, 2009 Share Posted February 1, 2009 I would assume that all these images are inside "Images/Random/" folder. If so, you might need to add a slash at the end of your $image_folder string. // Change to the location of the folder containing the images $image_folder = "images/random/"; // added a slash at the end The above will point the image to "images/random/{random_number}.gif Hope it helps Regards, LPM Link to comment https://forums.phpfreaks.com/topic/143395-random-image-not-working/#findComment-752137 Share on other sites More sharing options...
mike12255 Posted February 1, 2009 Author Share Posted February 1, 2009 actually to be honset i dont even use that line, i ment to take that out. Link to comment https://forums.phpfreaks.com/topic/143395-random-image-not-working/#findComment-752149 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.