Jump to content

Recommended Posts

Hi!

 

Im using an random image script which works fine but that I want to edit a bit. I have edited it a bit so when you click on a image you get a fullsize in a popup. The problem is that the image in the popup is also random and not always a bigger copy of the thumbnail, the smaller one you clicked on as I want:

 

see it live here, and I think you will understand what I want to achieve:

see it here

 

the code Im using is:

randim.php

<?php
/* The default folder with images */
$settings['img_folder'] = 'bildermini/';

/* File types (extensions) to display */
$settings['img_ext'] = array('.jpg','.gif','.png');

/*
   How to display the images?
   0 = print just the image path (for includes), like: images/test.jpg
   1 = redirect to the image, when using: <img src="randim.php" />
*/
$settings['display_type'] = 1;

/* Allow on-the-fly settings override? 0 = NO, 1 = YES */
$settings['allow_otf'] = 1;

/*******************************************************************************

/* Override type? */
if ($settings['allow_otf'] && isset($_GET['type']))
{
$type = intval($_GET['type']);
}
else
{
$type = $settings['display_type'];
}

/* Override images folder? */
if ($settings['allow_otf'] && isset($_GET['folder']))
{
$folder = htmlspecialchars(trim($_GET['folder']));
    if (!is_dir($folder))
    {
    	$folder = $settings['img_folder'];
    }
}
else
{
$folder = $settings['img_folder'];
}

/* Make sure images fodler ends with an '/' */
if (substr($folder,-1) != '/')
{
$folder.='/';
}

/* Get a list of all the image files */
$flist = array();
foreach($settings['img_ext'] as $ext)
{
    $tmp = glob($folder.'*'.$ext);
    if (is_array($tmp))
    {
    	$flist = array_merge($flist,$tmp);
    }
}

/* If we have any images choose a random one, otherwise select the "noimg.gif" image */
if (count($flist))
{
$src = $flist[array_rand($flist)];
}
else
{
$src = 'noimg.gif';
}

/* Output the image according to the selected type */
if ($type)
{
header('Location:'.$src);
    exit();
}
else
{
echo $src;
}
?>

 

and for calling 3 random images:

test.php

<ol>
click for bigger image:
<li>
<a class="fancy" rel="fancy" href="<?php $_GET['type']=0; $_GET['folder']='bilderstora'; include 'randim.php'; ?>"><img border='0' src="<?php $_GET['type']=0; $_GET['folder']='bildermini'; include 'randim.php'; ?>"></a></p>
</li>

<li>
<a class="fancy" rel="fancy" href="<?php $_GET['type']=0; $_GET['folder']='bilderstora'; include 'randim.php'; ?>"><img border='0' src="<?php $_GET['type']=0; $_GET['folder']='bildermini'; include 'randim.php'; ?>"></a></p>
</li>

<li>
<a class="fancy" rel="fancy" href="<?php $_GET['type']=0; $_GET['folder']='bilderstora'; include 'randim.php'; ?>"><img border='0' src="<?php $_GET['type']=0; $_GET['folder']='bildermini'; include 'randim.php'; ?>"></a></p>
</li>
</ol>

 

how do I edit the code so I get the same image on the link as it is on the thumbnail?

 

the images are stored in:

bildermini/ (thumbnails)

bilderstora/ (big image)

 

thanks for your help!

 

Perik

Link to comment
https://forums.phpfreaks.com/topic/198025-probably-pretty-easy-solved-php-issue/
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.