Jump to content

Random image not working!


mike12255

Recommended Posts

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

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

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.