Jump to content


Photo

need a little help with a PHP gallery script I'm making


  • Please log in to reply
No replies to this topic

#1 TheChihuahua

TheChihuahua
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 September 2006 - 03:57 AM

I'm making a PHP image gallery script, I got all the basic stuff done (make the thumbnails and the txt files for information) and it desplays them correctly, but now I want to add another feature, multiple galeries on 1 file

What I'm thinking is that if you put the information in the URL (www.site.com/gallery?gallery=cars) it will go only to that gallery, but if it's blank it will display all galeries. I get get it to display different galleries with the information passed through the URL but I can't think of a way to have it display all galeries.

Here is the code I am using for the gallery, it's not the neatest because I had to play around with it a bit to make the thumbnails work right, but if you want to look at it to see how I'm doing it and give me some help on hwo to make it display all the images i'd appriciate it (this cod edosen't have the multiple gellery through the URL code in it yet because I don't know how to do it all.
<?php
$target_folder = 'img/';
$per_row = 4;   
// file_name_no_ext = Filename without the exstension
// file_name_full = Filename with the exstension
$no_title_text = 'file_name_no_ext';
$no_desc_text = '';
$thumb_max_width = 125;
$thumb_max_height = 175;
?>
<?php
echo '<center><table border="0px" width="90px" cellspacing="5px">';
$folder = opendir($target_folder);
if (!$folder)
die('An Error has Occured!');
// While there are things in the folder get their names
while (($file = readdir($folder)) != false) {
if (strpos($file, '.jpg')>1 != strpos($file,'_thumb')) {
// Seperate file names into name and type
$filename = explode(".", $file);
// Determine file locations
$thumbfile = "$target_folder$filename[0]_thumb.$filename[1]";
$fullfile = "$target_folder$filename[0].$filename[1]";
$textfile = "$target_folder$filename[0].txt";
//get image dimensions
// there is a better method, redo later
$imagedimensions = getimagesize("$fullfile");
// Check for thumb and information file

// Check for thumb and make if not there
	if (file_exists($thumbfile)) {} else {
	   
	   $file = "$target_folder$filename[0].$filename[1]";
	   list($origwidth, $origheight) = getimagesize($fullfile) ;
	   
	   $origratio = $origwidth/$origheight;
	   $modwidth = $thumb_max_width/$origratio;
	   $modheight = $thumb_max_height*$origratio;
	   $modratio = $thumb_max_width/$thumb_max_height;
	   
	   //if the images are biggger in any dimension than the thumb max sizes
	     if ($origwidth > $thumb_max_width or $origheight > $thumb_max_height) {
	   
	       // resize
	       $per_x = $origwidth / $thumb_max_width;
	       $per_y = $origheight / $thumb_max_height;
	       if ($per_y > $per_x) {
	         $modwidth = $origwidth / $per_y;
	   $modheight = $thumb_max_height;
	       }
	       else {
	         $modheight = $origheight / $per_x;
	    $modwidth = $thumb_max_width;
	      }}
	      else {
	    $modheight = $origheight;
	    $modwidth = $origwidth;
	      }
	   
	   $tn = imagecreatetruecolor($modwidth, $modheight) ;
	   $image = imagecreatefromjpeg($fullfile) ;
	   imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $origwidth, $origheight) ;
	   
	   imagejpeg($tn, "$target_folder$filename[0]_thumb.$filename[1]", 100) ;
	   }
	   
// Check for text file if not there make it
	if (file_exists($textfile)) {}
	   else { fopen($textfile,'w+');} 

// Find the image title and description if there is one $imageinfo[0]=title $imageinfo[1]=desc
if (file_exists($textfile)) {
$imageinfo = file($textfile);
foreach ($imageinfo as $imageinfoline_num);}

//check if it's the start of a line, if so insert apprpriate HTML code
if ($line == 0) { echo '<tr>'; $line = 0;}

// Make the HTML code of the image table cells using alternated for title and desc if one dosen't exsist
echo '<td align="center" valign="middle">';
echo '<a href="', $fullfile , '">';
echo '<img border="0px" src="' , $thumbfile , '" alt="';
	if ($imageinfo[0] != '')
	   {echo $imageinfo[0];} else {echo $filename[0];}
echo '"></img><br>';
	if ($imageinfo[0]!='')
	   {echo $imageinfo[0];}
	elseif ($no_title_text == 'file_name_no_ext')
	   {echo $filename[0];}
	elseif ($no_title_text == 'file_name_full')
	   {echo $filename[0] , '.' , $filename[1];}
	elseif ($no_title_text == '')
	   {echo '';}
echo '</a><span  style="font-size: 7pt;">';
	if ($imageinfo[2] != '')
	   {echo '<br>', $imageinfo[2];}
	elseif ($no_desc_text == '')
	   {echo '';}
	else {echo '<br>', $no_desc_text;}
echo '</span>';
echo '</td>';

// check if it's the end of the line, if so inser appropriate HTML code
$line = $line + 1;
if ($line == $per_row) { echo '</tr>'; $line = 0;}
$totalimages = $totalimages + 1;
}}
die('done');
echo 'Images: ', $totalimages;
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users