Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Reply
 
Thread Tools
Old 10-06-07, 05:12 PM   #1
HarryDude
Registered User
 
Join Date: Jul 2005
Posts: 79
Red face PHP Gallery help

I used a PHP gallery tutorial a while back and found I could do more with it. At the moment it does exactly what I want it to do except for one cosmetic error which causes it to look dodgy.

www.harrydude.co.nr/gallerytest.php

Have a look at that, at the far right of the thumbnails it tries to make an image out of the path to the gallery folder :\ its a small error but I can't get rid of it.



I do have a work around but it requires me to have two seperate codes. (found on the actual gallery link on the site.)

Here's the script:
Code:
<?
$path = "gallery";
$files = "0";
$handle=opendir($path);
while ($file = readdir($handle)) {
if(!is_dir($path."/".$file) && $file != "." && $file!="..") {
$extension = explode (".", $file);
$extension_i = (count($extension) - 1);
$ext = $extension[$extension_i];
if($ext=="jpg"||$ext=="jpeg"||$ext=="JPG"||$ext=="JPEG") {
$images[$files] = $file;
$files++;
}
}
}
if(!$_GET["i"]) {
foreach($images as $image) {
$source = $path."/".$image;
$tsource = "thumbs/".$image;
$stsource = "small/".$image;
$thumbnail_h = "100";
$quality = "60";
$sthumbnail_h = "650";
$squality = "100";
if(file_exists($source)&&!file_exists($tsource)&&!file_exists($stsource)) {
$size = getimagesize($source);
$w = round($size[0]/($size[1]/$thumbnail_h));
$h = $thumbnail_h;
$resize = imagecreatetruecolor($w, $h);
$sw = round($size[0]/($size[1]/$sthumbnail_h));
$sh = $sthumbnail_h;
$sresize = imagecreatetruecolor($sw, $sh);
switch ($size['mime']) {
case 'image/jpeg':
$im = imagecreatefromjpeg($source);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
imagecopyresampled($sresize, $im, 0, 0, 0, 0, $sw, $sh, $size[0], $size[1]);
imagejpeg($resize, 'thumbs/'.$image, $quality);
imagejpeg($sresize, 'small/'.$image, $squality);
break;
case 'image/png':
$im = imagecreatefrompng($source);
imagecopyresampled($resize, $im, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
imagecopyresampled($sresize, $im, 0, 0, 0, 0, $sw, $sh, $size[0], $size[1]);
imagepng($resize, 'thumbs/'.$image, $quality);
imagepng($sresize, 'thumbs/'.$image, $squality);
break;
}
imagedestroy($im);
}
echo '<a href="?i='.$image.'"><img src="'.$tsource.'" border="0"></a> 
';
}
}
echo '<a href="'.$path.'/'.$_GET["i"].'" target="_blank"><img src="small/'.$_GET["i"].'" border="0"></a>';
if($_GET["i"]&&file_exists($path.'/'.$_GET["i"]))
$id = array_search($_GET["i"],$images);
$files2 = $files-1;
if($id>"0"&&$id<$files2) {
$next_id = $id+1;
$prev_id = $id-1;
echo '<div align="center">';
echo '<br><a href="?i='.$images[$prev_id].'"><b>Previous</b></a><b>: :</b><a href="?i='.$images[$next_id].'"><b>Next</b></a><br><br><b><a href="gallerytest.php">Back to Main Gallery</a></b>';
}
if($id=="0") {
$next_id = "1";
echo '<br><b>Previous: :</b><a href="?i='.$images[$next_id].'"><b>Next</b></a><br><br><b><a href="gallerytest.php">Back to Main Gallery</a></b>';
}
if($id==$files2) {
$prev_id = $files2-1;
echo '<br><a href="?i='.$images[$prev_id].'"><b>Previous</b></a><b>: :Next</b><br><br><b><a href="gallerytest.php">Back to Main Gallery</a></b>';
}
echo '</div>';
?>
Could anyone locate the problem for me? I'm a noob at php and can go just about as far as editing a script to do more of what I want it to do. (in this case I made it resize the source image twice, one for thumbnails and one for viewing on the site, and then a link from that to the original in a new window)

To test the gallery youreself make 3 folders on the server: 'gallery', 'thumbs' and 'small'. Save the script as 'gallerytest.php' and upload the images to the 'gallery' folder .

Images are just tests btw.
HarryDude is offline   Reply With Quote
Old 10-07-07, 09:38 AM   #2
QuakerX10
Registered User
 
Join Date: Jan 2005
Location: Amman, Jordan
Posts: 48
Default Re: PHP Gallery help

Didn't run it or anything, but try removing this line:
echo '<a href="'.$path.'/'.$_GET["i"].'" target="_blank"><img src="small/'.$_GET["i"].'" border="0"></a>';
QuakerX10 is offline   Reply With Quote
Old 10-07-07, 09:55 AM   #3
pross
 
pross's Avatar
 
Join Date: Mar 2007
Posts: 183
Default Re: PHP Gallery help

try:
if ($_GET["i"]){echo '<a href="'.$path.'/'.$_GET["i"].'" target="_blank"><img src="small/'.$_GET["i"].'" border="0"></a>';}
__________________
CPU: i7 2600k @ 4.4Ghz GPU: GTX 560ti 2G SLI PPU: GTX260 RAM: 16G Corsair Vengeance MOBO: P8Z68-V PRO GEN3 BOX: Cosmos S Cooling: Corsair H100 SSD: Corsair 120G ForceGT
pross is offline   Reply With Quote
Old 10-07-07, 10:17 AM   #4
HarryDude
Registered User
 
Join Date: Jul 2005
Posts: 79
Default Re: PHP Gallery help

Omg cheers pross it actually worked
HarryDude is offline   Reply With Quote
Old 10-07-07, 11:17 AM   #5
pross
 
pross's Avatar
 
Join Date: Mar 2007
Posts: 183
Default Re: PHP Gallery help

of course it did
__________________
CPU: i7 2600k @ 4.4Ghz GPU: GTX 560ti 2G SLI PPU: GTX260 RAM: 16G Corsair Vengeance MOBO: P8Z68-V PRO GEN3 BOX: Cosmos S Cooling: Corsair H100 SSD: Corsair 120G ForceGT
pross is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Planetside 2: A Gallery Of MAX, Comparisons, Tanks News Archived News Items 0 05-30-12 02:40 PM

All times are GMT -5. The time now is 03:01 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.