Imgae Thumbnail Link to Page

Discussion in 'PHP' started by joshrodgers, Sep 14, 2008.

  1. #1
    Basically I have put together a small image gallery (or that's what it will be). What I currently have is an upload script that creates a thumbnail. Then I have another piece that displays those thumbnails and links to the full image. Which is great. What I am trying to do is instead of linking to the full image I want to link to a page that contains the full image (so I can style the page and make the image look really nice). I have attached the code I am currently using. If anyone has any ideas please let me know. Thanks,

    Josh

    The upload/re-size script:
    <form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
            <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
            <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
    </form>
    <?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
    
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
    
              list($width, $height) = getimagesize($file) ; 
    
              $modwidth = 600; 
    
              $diff = $width / $modwidth;
    
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
    
              imagejpeg($tn, $save, 100) ; 
    
              $save = "images/thumbnails/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
    
              list($width, $height) = getimagesize($file) ; 
    
              $modwidth = 100; 
    
              $diff = $width / $modwidth;
    
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
    
              imagejpeg($tn, $save, 100) ; 
            echo "Large image: <img src='images/".$imagepath."'><br>"; 
            echo "Thumbnail: <img src='images/thumbnails/".$imagepath."'>"; 
          }
        }
    ?>
    PHP:
    The thumbnail display/full image link script:

    <html>
      <head>
        <title>Our Picture Share</title>
      </head>
    
    <body>
    
    <table bgcolor="#ffffff" width="900" cellpadding="0" cellspacing="0" margin="0" border="0">
      <tr>
        <td bgcolor="#ffffff" width="900" valign="top">
        <?php
        //displays images from our directory
        $handle = opendir ('./images/thumbnails');
        while (false !== ($file = readdir($handle))) {
            if($file != "." && $file != ".." && $file != basename(__FILE__)) {
                echo '<a href="./images/'.$file.'"/><img src="./images/thumbnails/'.$file.'"/></a><br /><br />';
            }
        }
        ?>
        </td>
      </tr>
    </table>
      
    </body>
    </html>
    PHP:
     
    joshrodgers, Sep 14, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Here's an idea for you to use if you want.


     echo '<a href="./images/'.$file.'"/><img src="./images/thumbnails/'.$file.'"/></a><br /><br />';
    
    
    Change that line ^ to this line.
    
    echo '<a href="imgview.php?img='.urlencode($file).'"><img src="./images/thumbnails/'.$file.'"/></a><br /><br />';
    
    
    
    
    =======================================
    
    in your new file (imgview.php)
    
    <?php
    
    if(isset($_GET['img'])){
    
    
    $img = $_GET['img'];
    
    }//end if
    
    
    //<--continue design your page 
    
    echo '<img src="images/'.$img.'">';
    
    
    ?>
    PHP:
     
    php-lover, Sep 14, 2008 IP
  3. joshrodgers

    joshrodgers Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That worked perfectly. Thanks for your help!

    Josh
     
    joshrodgers, Sep 15, 2008 IP