lapsinja Posted June 5, 2013 Share Posted June 5, 2013 Hey. I have 2 problems with thumbnails. Hope you could help to solve at least one of them 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? /** 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>'; } Really waiting for some answers. Thanks!!! Quote Link to comment Share on other sites More sharing options...
Eddy_J1 Posted June 5, 2013 Share Posted June 5, 2013 (edited) For number 2 I'd look around the line that says: function get_files($images_dir,$exts = array('jpg'))Note that $exts is an array Edited June 5, 2013 by Eddy_J1 Quote Link to comment Share on other sites More sharing options...
lapsinja Posted June 5, 2013 Author Share Posted June 5, 2013 (edited) Yes, I tried to add other extensions like : function get_files($images_dir,$exts = array('jpg', 'gif' ,'png')) but that is not working. what else should I add to this code to allow upload other file types? Edited June 5, 2013 by lapsinja Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.