Jump to content

Why Doesn't My Thumbnail Gallery Work


Joey46
 Share

Recommended Posts

I am trying to work out why my script does notmake thumbnails automatically please someone help me i am desperate below is my thumbnail script<?php$dir = 'Thumbs';$imgs = array(); echo "<ol>";if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(($file != '.') && ($file != '..')) { $imgs[] = $file; } } closedir($dh); }}rsort($imgs);foreach($imgs as $img_file){ echo "<img src='Thumbs/$img_file' alt='Click here to view larger image' />";} echo "</ol>"; ?>

Link to comment
Share on other sites

It would help if you explained what behavior you were expecting and what you're getting instead.I notice that you're creating a list, so maybe your images need to be surrounded in <li></li> tags. And since you want some click behavior, maybe also some <a></a> tags.If you're getting no output at all, you might try to print_r($imgs) and see if anything is even in there. Echoing $dh is a good idea, too. Always check if your file operations are even working.As for the thumbnail part -- is it important to your question that these are supposed to be thumbnails, or would there be a problem if the directory were filled with any kind of images.As I said, I don't know what exactly you're having trouble with.

Link to comment
Share on other sites

It would help if you explained what behavior you were expecting and what you're getting instead.I notice that you're creating a list, so maybe your images need to be surrounded in <li></li> tags. And since you want some click behavior, maybe also some <a></a> tags.If you're getting no output at all, you might try to print_r($imgs) and see if anything is even in there. Echoing $dh is a good idea, too. Always check if your file operations are even working.As for the thumbnail part -- is it important to your question that these are supposed to be thumbnails, or would there be a problem if the directory were filled with any kind of images.As I said, I don't know what exactly you're having trouble with.
this is what i need" if anyone loads a large image i need the script to turn the image into a thumbnail" so this means when i load a normal image i need it to turn into a thumbnail and when you click on the thumb nail you should get the normal image e.g loading a normal image should show a thumbnail then when you click on the thumbnail you get the normal image.Hope i made that sound clear enough
Link to comment
Share on other sites

Just know that the original picture and thumbnail are two different files, because if you display the image as a "thumbnail" (I placed quotes around it in thinking it is a thumbnail for making the dimensions smaller in the image tag) they are downloading the whole big image that you wanted them to see if they were to click on the "thumbnail" and this will take longer to download for them as they are downloading a lot of big picture files instead of the smaller thumbnail files. All this code looks like is to read the files from the folder Thumbs, and list them on a web page with an order list.Do you have any files in the Thumbs directory? Answer Deirdre's Dad's questions too.

Link to comment
Share on other sites

Just know that the original picture and thumbnail are two different files, because if you display the image as a "thumbnail" (I placed quotes around it in thinking it is a thumbnail for making the dimensions smaller in the image tag) they are downloading the whole big image that you wanted them to see if they were to click on the "thumbnail" and this will take longer to download for them as they are downloading a lot of big picture files instead of the smaller thumbnail files. All this code looks like is to read the files from the folder Thumbs, and list them on a web page with an order list.Do you have any files in the Thumbs directory? Answer Deirdre's Dad's questions too.
Yes i do have images in the thumbs directory
Link to comment
Share on other sites

Try ./Thumbs or ./Thumbs/
Well that works sort of with one problem it is still not showing the image as a thumb when you upload them. It is placing the image in the Graphics folder and not placing it in the Thumbs folder also, so i am thunking it is not making the thumbnails like it is supose to do for some reason. This is what i am trying to do Load an image the script is supose to make a thumbnail then it is spose to place the thumbnail in the right folder and place the larger image in the graphics folder.Does that make sense to you?
Link to comment
Share on other sites

The script you showed us will look into a folder of images that already exist, and then display them as items in a list. That's all.It doesn't upload anything, save anything, or convert large images to thumbnails. It doesn't say anything about a graphics folder.So if you're having problems with that part of your script, you'll have to show that part of your script.

Link to comment
Share on other sites

The script you showed us will look into a folder of images that already exist, and then display them as items in a list. That's all.It doesn't upload anything, save anything, or convert large images to thumbnails. It doesn't say anything about a graphics folder.So if you're having problems with that part of your script, you'll have to show that part of your script.
I am sorry i did not realise that was the error below is the upload PHP file<!doctype html public "-//w3c//dtd html 3.2//en"><html><head><title>Multiple image upload script from plus2net.com</title><meta name="GENERATOR" content="Arachnophilia 4.0"><meta name="FORMATTER" content="Arachnophilia 4.0"></head><body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><?$add="Graphics/$$userfile_name"; if(move_uploaded_file ($userfile, $add)){echo "Successfully uploaded the mage";chmod("$add",0777);}else{echo "Failed to upload file Contact Site admin to fix the problem";exit;}$n_width=100; $n_height=100; $tsrc="Thumbs/$userfile_name"; echo $tsrc;if (!($userfile_type =="image/JPEG" OR $userfile_type=="image/gif")){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";exit;}if (@$userfile_type=="image/gif"){$im=ImageCreateFromGIF($add);$width=ImageSx($im); $height=ImageSy($im); $newimage=imagecreatetruecolor($n_width,$n_height);imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);if (function_exists("imagegif")) {Header("Content-type: image/gif"); ImageGIF($newimage,$tsrc);}elseif (function_exists("imagejpeg")) {Header("Content-type: image/jpeg");ImageJPEG($newimage,$tsrc);}chmod("$tsrc",0777);}if($userfile_type=="image/pjpeg"){$im=ImageCreateFromJPEG($add); $width=ImageSx($im); $height=ImageSy($im); $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);ImageJpeg($newimage,$tsrc);chmod("$tsrc",0777);}?> </body></html>
Link to comment
Share on other sites

I am sorry i did not realise that was the error below is the upload PHP file<!doctype html public "-//w3c//dtd html 3.2//en"><html><head><title>Multiple image upload script from plus2net.com</title><meta name="GENERATOR" content="Arachnophilia 4.0"><meta name="FORMATTER" content="Arachnophilia 4.0"></head><body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><?$add="Graphics/$$userfile_name"; if(move_uploaded_file ($userfile, $add)){Ok that problem is fixed now thank all for your help much appreciatedecho "Successfully uploaded the mage";chmod("$add",0777);}else{echo "Failed to upload file Contact Site admin to fix the problem";exit;}$n_width=100; $n_height=100; $tsrc="Thumbs/$userfile_name"; echo $tsrc;if (!($userfile_type =="image/JPEG" OR $userfile_type=="image/gif")){echo "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";exit;}if (@$userfile_type=="image/gif"){$im=ImageCreateFromGIF($add);$width=ImageSx($im); $height=ImageSy($im); $newimage=imagecreatetruecolor($n_width,$n_height);imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);if (function_exists("imagegif")) {Header("Content-type: image/gif"); ImageGIF($newimage,$tsrc);}elseif (function_exists("imagejpeg")) {Header("Content-type: image/jpeg");ImageJPEG($newimage,$tsrc);}chmod("$tsrc",0777);}if($userfile_type=="image/pjpeg"){$im=ImageCreateFromJPEG($add); $width=ImageSx($im); $height=ImageSy($im); $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);ImageJpeg($newimage,$tsrc);chmod("$tsrc",0777);}?> </body></html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...