Its been asked before. But I still need help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Strongeo
Forum Newbie
Posts: 4
Joined: Wed May 16, 2007 7:25 am

Its been asked before. But I still need help!

Post by Strongeo »

So heres the problem, am using a small gallery script to create and manage photos. The script is meant to make thumbnails but it doesnt seem to be creating them at all! The /images/thumbs/ folder is consistently empty of anything! All I get is the image $title appearing on the gallery page while using '<?php displayList($phpfile, "thumbnail");?>'

Any help is appreciated!



This is the full code

Code: Select all

<?php

$username = "*****"; // Your preferred username.
$password = "*****"; // Your preferred password.
$path = "images/"; /* This is the path to the folder with the images. */
$xmlfile = "data.xml"; /* The path to the XML data file. */
$phpfile = "gallery.php"; /* The file used in links. */
$maxsize = 200000000; /* Max file size in bytes. */
$limit = 30; /* The limit when displaying descriptions in the administration. */
$allowedfiles = array("jpg", "gif", "png", "jpeg"); /* The types of images allowed for upload. */
$enableThumbnails = TRUE; /* TRUE is you want to enable thumbnails, FALSE if you don't. FALSE is default to save system resources. You can enable this at any time. */
$thumbnailwidth = 150; /* The width of the thumbnail in pixels or percent. Height will be calculated accordingly. */
$thumbnailquality = 100; /* Thumbnail quality. 100 is the highest, 0 is the lowest. Only applies to JPG images. */

/* End setup */

/* #########################################
   #### BEGIN PUBLIC GALLERY FUNCTIONS. ####
   ######################################### */
   
	function displayTitle($id) {
		global $title;
		echo $title[$id];
	}
	function displayImage($id, $type = "full") {
		global $description, $path, $name;
		if ($type == "thumbnail") {
			$imgpath = "{$path}thumbs/{$name[$id]}";
		} else {
			$imgpath = "{$path}{$name[$id]}";
		}
		$img = @getimagesize($imgpath);
		echo "<img src=\"{$imgpath}\" width=\"{$img[0]}\" height=\"{$img[1]}\" alt=\"{$description[$id]}\" />";
	}
	function displayRandomImage($phpfile, $type = "full") {
		global $description, $path, $name;
		srand((float) microtime() * 10000000);
		$id = array_rand($name, 1);
		if ($type == "thumbnail") {
			$imgpath = "{$path}thumbs/{$name[$id]}";
		} else {
			$imgpath = "{$path}{$name[$id]}";
		}
		$img = @getimagesize($imgpath);
		echo "<a href=\"{$phpfile}?id={$id}\"><img src=\"{$imgpath}\" width=\"{$img[0]}\" height=\"{$img[1]}\" alt=\"{$description[$id]}\" /></a>";
	}
	function displayDescription($id) {
		global $description;
		echo "{$description[$id]}";
	}
	function displayCategories($phpfile) {
		global $categories, $category, $name, $cat;
		for ($i=0;$i<count($categories);$i++) {
			UnSet($antal);
			for ($z=0;$z<count($name);$z++) {
				if ($cat[$z] == $i) {
					$antal++;
				}
			}
			if (IsSet($category) && $i == $category) {
				echo "<li class=\"current\">{$categories[$i]} ({$antal})</li>";
			} else {
				echo "<li><a href=\"{$phpfile}?category={$i}\">{$categories[$i]} ({$antal})</a></li>";
			}
		}
	}
	function displayCategory($id) {
		global $category, $categories;
		if (IsSet($category)) {
			echo $categories[$id];
		} else {
			echo "All Photos";
		}
	}
	function displayList($phpfile, $linktitle = "number") {
		global $name, $id, $category, $cat, $title, $path;
		for ($i=0;$i<count($name);$i++) {
			if ($i == $id) {
				if ($linktitle == "thumbnail") {
					$size = @getimagesize("{$path}thumbs/{$name[$id]}");
					echo "<li class=\"current\"><img src=\"{$path}thumbs/{$name[$id]}\" alt=\"{$title[$i]}\" {$size[3]} /></li>";
				} elseif ($linktitle == "number") {
					echo "<li class=\"current\">{$i}</li>";
				} else {
					echo "<li class=\"current\">{$title[$i]}</li>";
				}
			} else {
				if (IsSet($category)) {
					if ($category == $cat[$i]) {
						if ($linktitle == "thumbnail") {
							$size = @getimagesize("{$path}thumbs/{$name[$i]}");
							echo "<li><a href=\"{$phpfile}?id={$i}&category={$category}\"><img src=\"{$path}thumbs/{$name[$i]}\" alt=\"{$title[$i]}\" {$size[3]} /></a></li>";
						} elseif ($linktitle == "number") {
							echo "<li><a href=\"{$phpfile}?id={$i}&category={$category}\">{$i}</a></li>";
						} else {
							echo "<li><a href=\"{$phpfile}?id={$i}&category={$category}\">{$title[$i]}</a></li>";
						}
					}
				} else {
					if ($linktitle == "thumbnail") {
						$size = @getimagesize("{$path}thumbs/{$name[$i]}");
						echo "<li><a href=\"{$phpfile}?id={$i}\"><img src=\"{$path}thumbs/{$name[$i]}\" alt=\"{$title[$i]}\" {$size[3]} /></a></li>";
					} elseif ($linktitle == "number") {
						echo "<li><a href=\"{$phpfile}?id={$i}\">{$i}</a></li>";
					} else {
						echo "<li><a href=\"{$phpfile}?id={$i}\">{$title[$i]}</a></li>";
					}
				}
			}
		}
	}
	function displayNextCategory($category, $phpfile, $linktitle) {
		global $categories;
		if (is_array($categories) && count($categories) > 1) {
			if (!IsSet($category)) {
				echo "<a href=\"{$phpfile}?category=0\">{$linktitle}</a>";
			} else {
				$nextid = $category+1;
				if (IsSet($categories[$nextid])) {
					echo "<a href=\"{$phpfile}?category={$nextid}\">{$linktitle}</a>";
				} else {
					echo "<a href=\"{$phpfile}?category=0\">{$linktitle}</a>";
				}
			}
		}
	}
	function displayPrevCategory($category, $phpfile, $linktitle) {
		global $categories;
		if (is_array($categories) && count($categories) > 1) {
			if (!IsSet($category) || $category == 0) {
				// Get last category.
				end($categories);
				$previd = each($categories);
				$previd = $previd["key"];
				reset($categories);
				echo "<a href=\"{$phpfile}?category={$previd}\">{$linktitle}</a>";
			} else {
				$previd = $category-1;
				echo "<a href=\"{$phpfile}?category={$previd}\">{$linktitle}</a>";
			}
		}
	}
	function displayNextLink($id, $phpfile, $linktitle) {
		global $name, $category, $cat;
		if (!IsSet($category)) {
			if ($id == count($name)-1) {
				$nextid = 0;
			} else {
				$nextid = $id+1;
			}
		} else {
			for ($i=0;$i<count($name);$i++) {
				if ($category == $cat[$i]) {
					$nextidarr[] = $i;
				}
			}
			ksort($nextidarr);
			reset($nextidarr);
			foreach ($nextidarr as $key => $value) {
				if ($value == $id) {
					if(next($nextidarr)) {
						$nextid = each($nextidarr);
					} else {
						reset($nextidarr);
						$nextid = each($nextidarr);
					}
					$nextid = "{$nextid["value"]}&category={$category}";
					break;
				}
				next($nextidarr);
			}
		}
		echo "<a href=\"{$phpfile}?id={$nextid}\">$linktitle</a>";
	}
	function displayPrevLink($id, $phpfile, $linktitle) {
		global $name, $category, $cat;
		if (!IsSet($category)) {
			if ($id == 0) {
				$previd = count($navn)-1;
			} else {
				$previd = $id-1;
			}
		} else {
			for ($i=0;$i<count($name);$i++) {
				if ($category == $cat[$i]) {
					$previdarr[] = $i;
				}
			}
			ksort($previdarr);
			reset($previdarr);
			foreach ($previdarr as $key => $value) {
				if ($value == $id) {
					if ($key == 0) {
						end($previdarr);
						$previd = each($previdarr);
						$previd = "{$previd["value"]}&category={$category}";
						break;
					} else {
						prev($previdarr);
						$previd = each($previdarr);
						$previd = "{$previd["value"]}&category={$category}";
						break;
					}
				}
				next($previdarr);
			}
		}
		echo "<a href=\"{$phpfile}?id={$previd}\">$linktitle</a>";
	}
	
	
/* ##############################################################################
   #### FUNCTIONS & SETTINGS USED BY BOTH PUBLIC GALLERY AND ADMINISTRATION. ####
   ############################################################################## */
$self = basename($_SERVER["PHP_SELF"]);
function parseFile($xmlfile, $start, $end, $cdata) { /* This function parses the xml data file. */
	global $xml_parser;
	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, $start, $end);
	xml_set_character_data_handler($xml_parser, $cdata);
	$fp = @fopen($xmlfile, "r") or die("Cannot locate XML data file: {$xmlfile}");
	while ($data = fread($fp, filesize($xmlfile))) {
		if (!xml_parse($xml_parser, $data, feof($fp))) {
		    die(sprintf("XML error: %s at line %d",	xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
	    }
	}
	xml_parser_free($xml_parser);
}
function startImages($parser, $name, $a) { /* This function is executed everytime an xml start tag is met. */
	global $currentTag, $imgId, $cId;
	$currentTag = strtolower($name);
	if ($currentTag == "image") {
		$imgId = $a["ID"];
	} elseif ($currentTag == "category") {
		$cId = $a["CID"];
	}
}
function imgData($parser, $data) { /* This function is executed on all xml content. */
	global $currentTag, $imgId, $name, $title, $description, $cat, $categories, $cId;
	switch($currentTag) {
		case "file" :
			$name[$imgId] = $data;
			break;
		case "title" :
			$title[$imgId] = $data;
			break;
		case "description" :
			$description[$imgId] = $data;
			break;
		case "imgcategory" :
			$cat[$imgId] = $data;
			break;
		case "category" :
			$categories[$cId] = $data;
			break;
		default :
			break;
	}
}
function endElement($parser, $name) { /* This function is executed everytime an xml end tag is met. */
	global $currentTag, $status;
	$currentTag = "";
}
// The XML file is parsed and the content is put into arrays so we can access it easily later.
parseFile($xmlfile, "startImages", "endElement", "imgData");

// For the public gallery we set the id and category variables if they haven't been set in the URL.
if (!IsSet($_GET["id"]) || $_GET["id"] == "") {
	$id = 0;
} else {
	$id = $_GET["id"];
}
// If no category is set in the URL we unset the $category variable.
if (!IsSet($_GET["category"]) || $_GET["category"] == "") {
	UnSet($category);
} else {
	$category = $_GET["category"];
	if ($category != $cat[$id]) {
		for($i=0;$i<count($name);$i++) {
			if ($category == $cat[$i]) {
				$id = $i;
				break;
			}
		}
	}
}
Last edited by Strongeo on Wed May 16, 2007 2:53 pm, edited 1 time in total.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

First off, posting in bold with a larger font does not make your post stand out.

In regards to your actual post; have you got GD installed/enabled?
Strongeo
Forum Newbie
Posts: 4
Joined: Wed May 16, 2007 7:25 am

Post by Strongeo »

jayshields wrote:First off, posting in bold with a larger font does not make your post stand out.

In regards to your actual post; have you got GD installed/enabled?
Sorry I was just trying to differentiate between the code and what I was asking.

As for GD, Yes it is installed.

Thanks for the help.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Are you certain? Run a script with:

Code: Select all

phpinfo();
in it and make sure it mentions that GD is installed.

Have you tried to debug it at all? A good start would be to add

Code: Select all

error_reporting(E_ALL);
to the top of the script and see if any notices/warnings are produced.
Strongeo
Forum Newbie
Posts: 4
Joined: Wed May 16, 2007 7:25 am

Post by Strongeo »

The PHP info had GD enabled and installed. But I got the following error when debugging;

Notice: Undefined variable: antal in publish.php on line 57

Which is this little snippet;

Code: Select all

function displayCategories($phpfile) {
		global $categories, $category, $name, $cat;
		for ($i=0;$i<count($categories);$i++) {
			UnSet($antal);
			for ($z=0;$z<count($name);$z++) {
				if ($cat[$z] == $i) {
					$antal++;
				}
Im not entirely sure how to fix it, and it doesnt seem to have alot to do with the generating of thumbnails.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

It's hard to judge what's going on without seeing more code but generally unset() is pretty useless, and probably not a good idea for you to use it at all when it's being referenced only a few lines below.

Just comment out the unset() line and see what happens.

Edit: Actually, your code is pretty messed up. I can't understand what's going on there at all. Maybe you forgot to add $antal to the global line?
Last edited by jayshields on Wed May 16, 2007 4:01 pm, edited 1 time in total.
Strongeo
Forum Newbie
Posts: 4
Joined: Wed May 16, 2007 7:25 am

Post by Strongeo »

Ahh thanks so much, Worked straight away.. strange! Thanks alot for the help!
Post Reply