SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member lapsinja's Avatar
    Join Date
    Jun 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation problems with thumbnails

    Hey. I just started to learn php and I have 2 problems with thumbnails that I've been trying to fix for days now. Hope you could help to solve at least one of them. This is very very important for me, so I would really appreciate if you helped me!!!! please

    1.I have made a form on my website where the user can upload image and add some extra information. So I made thumbnails for uploaded images that are stored in folder (they're stored in the database as well, but these thumbnails are linked with the folder not database) and when I click on the thumbnail I want it to show the big image and some data from database that was added when the user uploaded the image (like- name and date). Now when I click on a thumbnail it shows me all the data that's in the database- including other images as well. How to link a thumbnail that is made in folder with data from database? (thumbnails and original images have exact the same name).

    2. I used this script to create thumbnails, but it is only for .jpg images. What should I add to allow .png , .jpeg and .gif extensions as well?
    PHP Code:
    /** settings **/
    $images_dir 'images/';
    $thumbs_dir 'images_thumbs/';
    $thumbs_width 200;
    $images_per_row 3;






    /* function:  generates thumbnail */
    function make_thumb($src,$dest,$desired_width) {
        
    /* read the source image */
        
    $source_image imagecreatefromjpeg($src);
        
    $width imagesx($source_image);
        
    $height imagesy($source_image);
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */
        
    $desired_height floor($height*($desired_width/$width));
        
    /* create a new, "virtual" image */
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height);
        
    /* copy source image at a resized size */
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
        
    /* create the physical thumbnail image to its destination */

    }

    /* function:  returns files from dir */
    function get_files($images_dir,$exts = array('jpg')) {
        
    $files = array();
        if(
    $handle opendir($images_dir)) {
            while(
    false !== ($file readdir($handle))) {
                
    $extension strtolower(get_file_extension($file));
                if(
    $extension && in_array($extension,$exts)) {
                    
    $files[] = $file;
                }
            }
            
    closedir($handle);
        }
        return 
    $files;
    }

    /* function:  returns a file's extension */
    function get_file_extension($file_name) {
        return 
    substr(strrchr($file_name,'.'),1);
    }



    /** generate photo gallery **/
    $image_files get_files($images_dir);
    if(
    count($image_files)) {
        
    $index 0;
        foreach(
    $image_files as $index=>$file) {
            
    $index++;
            
    $thumbnail_image $thumbs_dir.$file;
            if(!
    file_exists($thumbnail_image)) {
                
    $extension get_file_extension($thumbnail_image);
                if(
    $extension) {
                    
    make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
                }
            }
            echo 
    '<a href="',$images_dir.$file,'"><img src="',$thumbnail_image,'" /></a>';
        }
    }
    else {
        echo 
    '<p>There are no images in this gallery.</p>';


  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    A couple of things, first you need to allow this line to change based on the extension you receive.
    PHP Code:
        $source_image imagecreatefromjpeg($src); 
    There are imagecreatefromgif, and imagecreatefrompng implementations, so based on extension, use the correct one.

    So within make_thumb, get the extension
    PHP Code:
    $ext get_file_extension($src); 
    Then use a switch statement to call the correct function
    PHP Code:
    $source_image null;
    switch (
    strtolower($ext))
    {
      case 
    "jpg":
        
    $source_image imagecreatefromjpeg($src);
        break;
      case 
    "gif":
        
    $source_image imagecreatefromgif($src);
        break;
      case 
    "png":
        
    $source_image imagecreatefrompng($src);
        break;
      default:
        return;

    In the end, you end up with:
    PHP Code:
    /* function:  generates thumbnail */ 
    function make_thumb($src,$dest,$desired_width) { 
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
        
    /* create the physical thumbnail image to its destination */ 


    Then update the following line to include gif and png as well as jpg
    PHP Code:
    $exts = array('jpg'
    Should be
    PHP Code:
    $exts = array('jpg''gif''png'
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Member lapsinja's Avatar
    Join Date
    Jun 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you I changed the code, but something still is not right. This is how the code looks like now. Did I miss something? :
    PHP Code:
    /** settings **/
    $images_dir 'images/';
    $thumbs_dir 'images_thumbs/';
    $thumbs_width 200;
    $ext get_file_extension($src);


    /* function:  generates thumbnail */ 
    function make_thumb($src,$dest,$desired_width) { 
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
        
    /* create the physical thumbnail image to its destination */ 

    }  

    /* function:  returns files from dir */
    function get_files($images_dir,$exts = array('jpg''gif''png') ) {
        
    $files = array();
        if(
    $handle opendir($images_dir)) {
            while(
    false !== ($file readdir($handle))) {
                
    $extension strtolower(get_file_extension($file));
                if(
    $extension && in_array($extension,$exts)) {
                    
    $files[] = $file;
                }
            }
            
    closedir($handle);
        }
        return 
    $files;
    }

    /* function:  returns a file's extension */
    function get_file_extension($file_name) {
        return 
    substr(strrchr($file_name,'.'),1);
    }

    /** generate photo gallery **/
    $image_files get_files($images_dir);
    if(
    count($image_files)) {
        
    $index 0;
        foreach(
    $image_files as $index=>$file) {
            
    $index++;
            
    $thumbnail_image $thumbs_dir.$file;
            if(!
    file_exists($thumbnail_image)) {
                
    $extension get_file_extension($thumbnail_image);
                if(
    $extension) {
                    
    make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
                }
            }
            echo 
    '<a href="',$images_dir.$file,'" class="photo-link smoothbox" rel="gallery"><img src="',$thumbnail_image,'" /></a>';
            if(
    $index $images_per_row == 0) { echo '<div class="clear"></div>'; }
        }
        echo 
    '<div class="clear"></div>';
    }
    else {
        echo 
    '<p>There are no images in this gallery.</p>';


  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Yep, my bad. I missed a line and your interpretation of what I meant was incorrect.

    Change
    PHP Code:
    $ext get_file_extension($src);


    /* function:  generates thumbnail */ 
    function make_thumb($src,$dest,$desired_width) { 
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
        
    /* create the physical thumbnail image to its destination */ 


    To
    PHP Code:
    /* function:  generates thumbnail */ 
    function make_thumb($src,$dest,$desired_width) { 
        
    $ext get_file_extension($src);
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
        
    /* create the physical thumbnail image to its destination */ 


    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  5. #5
    SitePoint Member lapsinja's Avatar
    Join Date
    Jun 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed as you said, but it is still not working. now the code isn't creating thumbnails at all, even not for .jpg files :/

  6. #6
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    677
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    I don't see $desired_width defined.

  7. #7
    SitePoint Member lapsinja's Avatar
    Join Date
    Jun 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, I defined it but that doesn't seem to be the problem. Can someone see where is the mistake? I did work with just jpg files before my attempt to add other extensions as well ,but now it is not working at all.
    PHP Code:
    /** settings **/
    $images_dir 'images/';
    $thumbs_dir 'images/images_thumbs/';
    $thumbs_width 200;
    $images_per_row 3;
    $desired_width200;

    /* function:  generates thumbnail */ 
    function make_thumb($src,$dest,$desired_width) { 
        
    $ext get_file_extension($src);
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
        
    /* create the physical thumbnail image to its destination */ 

    }  

    /* function:  returns files from dir */
    function get_files($images_dir,$exts = array('jpg''gif''png')) {
        
    $files = array();
        if(
    $handle opendir($images_dir)) {
            while(
    false !== ($file readdir($handle))) {
                
    $extension strtolower(get_file_extension($file));
                if(
    $extension && in_array($extension,$exts)) {
                    
    $files[] = $file;
                }
            }
            
    closedir($handle);
        }
        return 
    $files;
    }

    /* function:  returns a file's extension */
    function get_file_extension($file_name) {
        return 
    substr(strrchr($file_name,'.'),1);
    }



    /** generate photo gallery **/
    $image_files get_files($images_dir);
    if(
    count($image_files)) {
        
    $index 0;
        foreach(
    $image_files as $index=>$file) {
            
    $index++;
            
    $thumbnail_image $thumbs_dir.$file;
            if(!
    file_exists($thumbnail_image)) {
                
    $extension get_file_extension($thumbnail_image);
                if(
    $extension) {
                    
    make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
                }
            }
            echo 
    '<a href="gallery.php" class="photo-link smoothbox" rel="gallery"><img src="',$thumbnail_image,'" /></a>';
            if(
    $index $images_per_row == 0) { echo '<div class="clear"></div>'; }
        }
        echo 
    '<div class="clear"></div>';
    }
    else {
        echo 
    '<p>There are no images in this gallery.</p>';


  8. #8
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    677
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Well I'm no expert on this but it seems to me you're missing the actual image creation after resized tmp is made. I added the imagejpeg($virtual_image,$dest,100); line and it seemed to work fine for me.

    PHP Code:
    function make_thumb($src,$dest,$desired_width) { 
        
    $ext get_file_extension($src);
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 
        
    /* create the physical thumbnail image to its destination */
        
    imagejpeg($virtual_image,$dest,100); 

    There's also the issue of where you're saying if thumb doesn't exist, then get extension of the file that doesn't exist, so it should be changed to the primary image.
    PHP Code:
            if(!file_exists($thumbnail_image)) {
                
    $extension get_file_extension($images_dir.$file);
                if(
    $extension) {
                    
    make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
                }
            } 

  9. #9
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Drummin View Post
    I don't see $desired_width defined.
    It doesn't need to be. It is using $thumbs_width which is defined.

    Quote Originally Posted by Drummin View Post
    Well I'm no expert on this but it seems to me you're missing the actual image creation after resized tmp is made. I added the imagejpeg($virtual_image,$dest,100); line and it seemed to work fine for me.
    Let's fix that so it works for multiple extensions:
    PHP Code:
    function make_thumb($src,$dest,$desired_width) { 
        
    $ext get_file_extension($src);
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 

        
    /* create the physical thumbnail image to its destination */
        
    switch (strtolower($ext))
        {
          case 
    "jpg":
        
    imagejpeg($virtual_image,$dest,100); 
            break;
          case 
    "gif":
        
    imagegif($virtual_image,$dest); 
            break;
          case 
    "png":
        
    imagepng($virtual_image,$dest,9); 
            break;
        }

    Quote Originally Posted by Drummin View Post
    There's also the issue of where you're saying if thumb doesn't exist, then get extension of the file that doesn't exist, so it should be changed to the primary image.
    You mis-read that. The get_file_extension is fine, as it is only dependent on $file being populated, which is. Yes, the path is bad, but that only matters for file_exists.[/QUOTE]

    Final code (I think)
    PHP Code:
    /** settings **/
    $images_dir 'images/';
    $thumbs_dir 'images/images_thumbs/';
    $thumbs_width 200;
    $images_per_row 3;

    /* function:  generates thumbnail */ 
    function make_thumb($src,$dest,$desired_width) { 
        
    $ext get_file_extension($src);
        
    /* read the source image */ 
        
    $source_image null;
        switch (
    strtolower($ext))
        {
          case 
    "jpg":
            
    $source_image imagecreatefromjpeg($src);
            break;
          case 
    "gif":
            
    $source_image imagecreatefromgif($src);
            break;
          case 
    "png":
            
    $source_image imagecreatefrompng($src);
            break;
          default:
            return;
        }

        
    $width imagesx($source_image); 
        
    $height imagesy($source_image); 
        
    /* find the "desired height" of this thumbnail, relative to the desired width  */ 
        
    $desired_height floor($height*($desired_width/$width)); 
        
    /* create a new, "virtual" image */ 
        
    $virtual_image imagecreatetruecolor($desired_width,$desired_height); 
        
    /* copy source image at a resized size */ 
        
    imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height); 

        
    /* create the physical thumbnail image to its destination */
        
    switch (strtolower($ext))
        {
          case 
    "jpg":
        
    imagejpeg($virtual_image,$dest,100); 
            break;
          case 
    "gif":
        
    imagegif($virtual_image,$dest,100); 
            break;
          case 
    "png":
        
    imagepng($virtual_image,$dest,100); 
            break;
        }
    }  

    /* function:  returns files from dir */
    function get_files($images_dir,$exts = array('jpg''gif''png')) {
        
    $files = array();
        if(
    $handle opendir($images_dir)) {
            while(
    false !== ($file readdir($handle))) {
                
    $extension strtolower(get_file_extension($file));
                if(
    $extension && in_array($extension,$exts)) {
                    
    $files[] = $file;
                }
            }
            
    closedir($handle);
        }
        return 
    $files;
    }

    /* function:  returns a file's extension */
    function get_file_extension($file_name) {
        return 
    substr(strrchr($file_name,'.'),1);
    }



    /** generate photo gallery **/
    $image_files get_files($images_dir);
    if(
    count($image_files)) {
        
    $index 0;
        foreach(
    $image_files as $index=>$file) {
            
    $index++;
            
    $thumbnail_image $thumbs_dir.$file;
            if(!
    file_exists($thumbnail_image)) {
                
    $extension get_file_extension($thumbnail_image);
                if(
    $extension) {
                    
    make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
                }
            }
            echo 
    '<a href="gallery.php" class="photo-link smoothbox" rel="gallery"><img src="',$thumbnail_image,'" /></a>';
            if(
    $index $images_per_row == 0) { echo '<div class="clear"></div>'; }
        }
        echo 
    '<div class="clear"></div>';
    }
    else {
        echo 
    '<p>There are no images in this gallery.</p>';

    Last edited by cpradio; Jun 6, 2013 at 17:19. Reason: Update parameters for image*
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  10. #10
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    677
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Yes cpradio I'm following that now. Nice job.

  11. #11
    SitePoint Member lapsinja's Avatar
    Join Date
    Jun 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you for helping me But something is still now working.
    I tried both codes.. the first one kind of works, but the thumbnails are duplicated - 2 instead of one.
    The second one creates the thumbnail in the thumbnail folder, but the thumbnail image for .png isn't working, it shows the broken image icon. But the thumbnails for.jpg files are working.

  12. #12
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Please post your version of the code, so we know what we are looking at (what to make sure there aren't any copy/paste typos).
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  13. #13
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Ah, the PNG issue is because 100 is not valid for the third parameter of imagepng. That needs to be a value between 0-9. 9 will produce the smallest filesize, 0 will produce the largest filesize. I ran 6 images through 0 and through 9 and they looked visually identical, so I suggest using 9.

    PHP Code:
    imagepng($virtual_image,$dest,9); 
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  14. #14
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    677
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Not sure if GIF has a third parameter. ???
    imagegif($virtual_image,$dest);

  15. #15
    SitePoint Member lapsinja's Avatar
    Join Date
    Jun 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, cpradio ! It works fine now, I can upload png images as well
    And back to the first question:
    Now when I click on the thumbnail it leads to all of the images from database..maybe you know how to link the thumbnails to the same image from the database? I don't want to show just the full image when user clicks on the thumbnail (just in case you say to link the thumbnail to the folder, not database), because I want it to show the image from the database + additional info that was uploaded together with the image.

  16. #16
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,069
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    You would need to pass an unique identifier to gallery.php (maybe the image name?) That you can then use to filter your query on that page (when present).

    Think gallery.php?image=my_image.png or something like that.

    Then your gallery.php would read it using $_GET['image'] and validate it/sanitize it, and then use it in a query to the database.
    Be sure to congratulate Patche on earning July's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •