TheChihuahua
-
Posts
1 -
Joined
-
Last visited
Never
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
need a little help with a PHP gallery script I'm making
in PHP Coding Help
Posted
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.
[code]<?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;
?>
[/code]