probably pretty easy solved php issue ...

Discussion in 'PHP' started by perik, Apr 8, 2010.

  1. #1
    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:
    katapultforlag.com/page.php?37

    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;
    }
    ?>
    PHP:
    and for calling it:
    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>
    
    Code (markup):
    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
     
    Last edited: Apr 8, 2010
    perik, Apr 8, 2010 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    In your test.php something like that:
    
    <?php
    $_GET['type']=0; 
    $_GET['folder']='bilderstora';
    include 'randim.php';
    //now you have large image in $src;
    // replace folder name assuming filename is the same
    $small = str_replace('bilderstora','bildermini',$src);
     ?>
    <ol>
    click for bigger image:
    <li>
    <a class="fancy" rel="fancy" href="<?=$src;?>"><img border='0' src="<?=$small;?>"></a></p>
    </li>
    <?php
    // new random image;
    include 'randim.php';
    //now you have large image in $src;
    // replace folder name assuming filename is the same
    $small = str_replace('bilderstora','bildermini',$src);
     ?>
    <li>
    <a class="fancy" rel="fancy" href="<?=$src;?>"><img border='0' src="<?=$small;?>"></a></p>
    </li>
    </ol>
    
    PHP:
     
    AsHinE, Apr 8, 2010 IP
  3. perik

    perik Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    worked! thanks a lot!!!
     
    perik, Apr 8, 2010 IP