thejj924 Posted May 25, 2010 Share Posted May 25, 2010 <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="thickbox.js"></script> <link rel="stylesheet" href="thickbox.css" type="text/css" media="screen" /> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <?php $columns = 4; $thmb_width = 150; $thmb_height = 120; function resizeImage($originalImage,$toWidth,$toHeight){ // Get the original geometry and calculate scales list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; // Recalculate new size with default ratio if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } function generateThumbnails(){ global $thmb_width,$thmb_height; // Open the actual directory if ($handle = opendir(".")) { // Read all file from the actual directory while ($file = readdir($handle)) { // Check whether tha actual item is a valid file if (is_file($file)){ // Check whether the actual image is a thumbnail if (strpos($file,'_th.jpg')){ $isThumb = true; } else { $isThumb = false; } if (!$isThumb) { // Process the file string $dirName = substr($file,0,strpos($file,basename($file))); if (strlen($dirName) < 1) $dirName = '.'; $fileName = basename($file); $fileMain = substr($fileName,0,strrpos($fileName,'.')); $extName = substr($fileName,strrpos($fileName,'.'), strlen($fileName)-strrpos($fileName,'.')); // Check if the actual file is a jpeg image if (($extName == '.jpg') || ($extName == '.jpeg')||($extName== '.JPG')){ $thmbFile = $dirName.'/'.$fileMain.'_th.jpg'; // If a thumbnail dosn't exists tahn create a new one if (!file_exists($thmbFile)){ imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80); } } } } } } } function getNormalImage($file){ $base = substr($file,0,strrpos($file,'_th.jpg')); if (file_exists($base.'.jpg')) return $base.'.jpg'; elseif (file_exists($base.'.jpeg')) return $base.'.jpeg'; else return ""; } function displayPhotos(){ global $columns; generateThumbnails(); $act = 0; // Open the actual directory if ($handle = opendir(".")) { // Read all file from the actual directory while ($file = readdir($handle)) { // Check whether tha actual item is a valid file if (is_file($file)){ // Check whether the actual image is a thumbnail if (strpos($file,'_th.jpg')){ ++$act; if ($act > $columns) { echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'" class="thickbox"><img src="'.$file.'" alt="'.$file.'"/></a></td>'; $act = 1; } else { echo '<td class="photo"><a href="'.getNormalImage($file).'"class="thickbox"><img src="><img src="'.$file.'" alt="'.$file.'"/></a></td>'; } } } } } } ?> <style type="text/css"> body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000; } a:link { color: #000; } a:visited { color: #000; } a:hover { color: #000; } a:active { color: #000; } .Main { Color:000; font:Arial, Helvetica, sans-serif; font-size:12pt; } --> </style></head> <body bgcolor="#555555" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><Center> <table width="805" bgcolor="#999999"> <tr><td><center> <table id="Table_01" width="800" height="200" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="7"> <img src="../images/banner_01.jpg" width="800" height="164" alt=""></td> </tr> <tr> <td><a href="../index2.html"><img src="../images/Untitled-1_02.jpg" width="100" height="36" border="0" alt=""></a></td> <td><a href="../models.html"><img src="../images/Untitled-1_03.jpg" width="100" height="36" border="0" alt=""></a></td> <td><a href="../access.html"><img src="../images/Untitled-1_04.jpg" width="100" height="36" border="0" alt=""></a></td> <td> <img src="../images/Untitled-1_05.jpg" width="200" height="36" border="0" alt=""></td> <td><a href="index.php"><img src="../images/Untitled-1_06.jpg" width="100" height="36" border="0" alt=""></a></td> <td><a href="../aboutus.html"><img src="../images/Untitled-1_07.jpg" width="100" border="0" height="36" alt=""></a></td> <td><a href="contact.html"><img src="../images/banner_08.jpg" width="100" border="0" height="36" alt=""></a></td> </tr> <tr> <td colspan="7"> <table align="center"><tr> <center><b><font size="11pt">Welcome to Our Photo Gallery</font></b></center> <?php displayPhotos(); ?> </table> </td> </tr> </table> </center></td></tr></table> </Center> </body> </html> when i view source on the page when uploaded it comes up as <td class="photo"><a href=""class="thickbox"><img src="><img src="boardtrackerrightside_th.jpg" alt="boardtrackerrightside_th.jpg"/></a></td><td class="photo"><a href=""class="thickbox"><img src="><img src="boardtrackerleftside_th.jpg" alt="boardtrackerleftside_th.jpg"/></a></td><td class="photo"><a href=""class="thickbox"><img src="><img src="beachcomberrightside_th.jpg" alt="beachcomberrightside_th.jpg"/></a></td><td class="photo"><a href=""class="thickbox"><img src="><img src="beachcomberleftside_th.jpg" alt="beachcomberleftside_th.jpg"/></a></td> Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/ Share on other sites More sharing options...
andrewgauger Posted May 25, 2010 Share Posted May 25, 2010 <img src="> should be removed from: echo '<td class="photo"><a href="'.getNormalImage($file).'"class="thickbox"><img src="> Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063232 Share on other sites More sharing options...
thejj924 Posted May 25, 2010 Author Share Posted May 25, 2010 ok i removed that but the <a href=""> is still blank, it should give the image any help there? <a href="" class="thickbox" rel="motocycleimages"><img src="boardtrackerrightside_th.jpg" alt="boardtrackerrightside_th.jpg"/></a> Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063237 Share on other sites More sharing options...
andrewgauger Posted May 25, 2010 Share Posted May 25, 2010 Well, why don't you put a url in between the quotes? Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063244 Share on other sites More sharing options...
thejj924 Posted May 25, 2010 Author Share Posted May 25, 2010 because its a gallery script that is suppose to read the images, and then pop up the images in a thickbox window, but it is not doing the window Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063250 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 You include the jquery & thickbox javascript, but you never use them in your own Javascript. Ken Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063254 Share on other sites More sharing options...
thejj924 Posted May 25, 2010 Author Share Posted May 25, 2010 http://pastie.org/976974 <- thickbox.js http://pastie.org/977037 <- jquery.js Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063255 Share on other sites More sharing options...
kenrbnsn Posted May 25, 2010 Share Posted May 25, 2010 Thanks. It wasn't clear that you were doing that. Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063257 Share on other sites More sharing options...
andrewgauger Posted May 25, 2010 Share Posted May 25, 2010 Generally jQuery just uses a href="#" and a class that lets jQuery know what to do. Make sure you put a space after the end quote and the word class too. Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063267 Share on other sites More sharing options...
thejj924 Posted May 25, 2010 Author Share Posted May 25, 2010 like <a href="'.getNormalImage($file).'" class="thickbox" Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063270 Share on other sites More sharing options...
andrewgauger Posted May 25, 2010 Share Posted May 25, 2010 Isn't getNormalImage() a function you created to return the path of the non-tumbed version of the file? Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063275 Share on other sites More sharing options...
thejj924 Posted May 25, 2010 Author Share Posted May 25, 2010 Isn't getNormalImage() a function you created to return the path of the non-tumbed version of the file? yeah, its not working though thats why i need help Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063278 Share on other sites More sharing options...
andrewgauger Posted May 25, 2010 Share Posted May 25, 2010 Found it: you need brackets around these lines: if (file_exists($base.'.jpg')) return $base.'.jpg'; elseif (file_exists($base.'.jpeg')) return $base.'.jpeg'; else return ""; as: if (file_exists($base.'.jpg')) {return $base.'.jpg'} elseif (file_exists($base.'.jpeg')) {return $base.'.jpeg'} else {return ""} I love using the bracketless if syntax for solid one liners, but you need the brackets for an if else OR if elseif else Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063282 Share on other sites More sharing options...
thejj924 Posted May 25, 2010 Author Share Posted May 25, 2010 i was able to fix myself, thanks anyways guys. Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063289 Share on other sites More sharing options...
jcbones Posted May 25, 2010 Share Posted May 25, 2010 I've never had a script to fail a one line bracketless syntax for if/elseif/else statements. Although, I agree that it is good practice to use brackets for all if/else statements. I tested your getNormalImage() function, and it seems to work correctly. I cannot test your displayPhotos() function, but did see some problems with it. You can compare the changes I made, some may be redundant and not needed, but ... function displayPhotos(){ global $columns; generateThumbnails(); $act = 0; // Open the actual directory if ($handle = opendir(".")) { // Read all file from the actual directory while (false !== ($file = readdir($handle))) { // Check whether tha actual item is a valid file if (is_file($file) && ($file != '.' || $file != '..')){ // Check whether the actual image is a thumbnail if (strpos($file,'_th.jpg') !== false){ ++$act; if ($act > $columns) { echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'" class="thickbox"><img src="'.$file.'" alt="'.$file.'"/></a></td>'; $act = 1; } else { echo '<td class="photo"><a href="'.getNormalImage($file).'"class="thickbox"><img src="><img src="'.$file.'" alt="'.$file.'"/></a></td>'; } } } } } } I see it is already fixed, but added this anyway. Since I spent time on it. Quote Link to comment https://forums.phpfreaks.com/topic/202876-help-with-my-image-gallery/#findComment-1063301 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.