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
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

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.