e2 Gallery - IPTC error

Hi,

I am receiving the following notifications and warnings from a PHP file that is included in the popular e2 Gallery download.

What do the error messages mean and how can I resolve them?


Please find the getimagesize.php file on the second post

<b>Warning</b>
: getimagesize(images/1_17th_july_2009/thumbs) [
<a href="function.getimagesize">function.getimagesize</a>
]: failed to open stream: Permission denied in
<b>C:\Inetpub\site\gallery\getfolders.php</b>
on line
<b>177</b>
<br/>
<br/>
<b>Notice</b>
: Undefined index: APP0 in
<b>C:\Inetpub\site\gallery\getfolders.php</b>
on line
<b>179</b>
<br/>
<br/>
<b>Notice</b>
: Undefined index: APP0 in
<b>C:\Inetpub\site\gallery\getfolders.php</b>
on line
<b>181</b>
<br/>
<a onclick="getstarted(, , 'imgloader', 4, '4', current_imgid);return false;" href="#">
</a>
<br/>
<b>Notice</b>
: Undefined index: APP0 in
<b>C:\Inetpub\site\gallery\getfolders.php</b>
on line
<b>179</b>
<br/>
<br/>
<b>Notice</b>
: Undefined index: APP0 in
<b>C:\Inetpub\site\gallery\getfolders.php</b>
on line
<b>181</b>
<br/>

Open in new window

LVL 4
wilson1000Asked:
Who is Participating?
 
Hube02Connect With a Mentor Commented:
At any rate, the reason for the first error is that the script is trying to open a file named "thumbs", this is likely on a windows machine and this file is a system file.
 
 It appears that the script is simply looping through all the files in a folder without regard to what type of files there are. There should be some checking here. I'm sure that the app is expecting to find nothing but image files in the directory and this file is throwing it off.

As far as the undefined index, there needs to be a check to ensure the index exists before trying to parse it, for instance line 108 of the code you posted

$iptc = iptcparse($info["APP13"]);

you should do something like

$iptc = array();
if (isset($info["APP13"])) {
  $iptc = iptcparse($info["APP13"]);
}

This insures that the index is set before trying to access it and it also sets a default value for $iptc in case the parse fails.

And it should be APP13 and not APP0, IPTC data is stored in APP13 if it exists.

Just a coincidence, I am currently working on a class that reads and writes IPTC data
0
 
wilson1000Author Commented:


function getImages($path, $galleryName) {
 
  $files = array();
   $fileNames = array();
   $i = 0;
   
   if (is_dir($path)) {
       if ($dh = opendir($path)) {
           while (($file = readdir($dh)) !== false) {
               if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
               $fullpath = $path . "/" . $file;
               $fkey = strtolower($file);
               while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
               $a = stat($fullpath);
               $files[$fkey]['size'] = $a['size'];
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
               $files[$fkey]['name'] = $file;
               $files[$fkey]['type'] = filetype($fullpath);
               $fileNames[$i++] = $fkey;
           }
           closedir($dh);
       } else die ("Cannot open directory:  $path");
   } else die ("Path is not a directory:  $path");
   sort($fileNames,SORT_STRING);
   $sortedFiles = array();
   $i = 0;
   $photos = array();
   foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
   
   	
	echo "var $galleryName = new Array() \n";
 
   $j = 0;
   foreach ($sortedFiles as $file) {
   	
	// get image sizes 
	list($width, $height, $type, $attr) = getimagesize($path."/".$file[name], $info);
	$size = $file[sizetext];
	$iptc = iptcparse($info["APP13"]);
	// iptc  info
	$iptc = iptcparse($info["APP13"]);
	$title = $iptc['2#005'][0];
	$description = $iptc['2#120'][0];
	$description = str_replace("\r", "<br/>", $description);
	$description = addslashes($description);
	$keywords = $iptc['2#025'][0];
	$author = $iptc['2#080'][0];
	$copyright = $iptc['2#116'][0];
		
		array_push($photos, $width);
		array_push($photos, $height);
		echo "$galleryName";echo"[".$j."]=['".$path."/".$file[name]."', '".$width."', '".$height."', '".$size."', '".$title."', '".$author."', '".$copyright."', '".$description."', '".$j."']\n";
		$j++;
	}
	echo "\n";
	echo "var currentwidth=".$photos[0].";\n";
	echo "var currentheight=".$photos[1].";";
	echo "\n";
 
}
 
 
function getfirstimage($path, $galleryName) {
 
  $files = array();
   $fileNames = array();
   $i = 0;
   
   if (is_dir($path)) {
       if ($dh = opendir($path)) {
           while (($file = readdir($dh)) !== false) {
               if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
               $fullpath = $path . "/" . $file;
               $fkey = strtolower($file);
               while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
               $a = stat($fullpath);
               $files[$fkey]['size'] = $a['size'];
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
               $files[$fkey]['name'] = $file;
               $files[$fkey]['type'] = filetype($fullpath);
               $fileNames[$i++] = $fkey;
           }
           closedir($dh);
       } else die ("Cannot open directory:  $path");
   } else die ("Path is not a directory:  $path");
   sort($fileNames,SORT_STRING);
   $sortedFiles = array();
   $i = 0;
   $photoarray = array();
   $photoinfo = array();
   foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
   echo'<div id="imgloader">';
   
   $j=0;
   foreach ($sortedFiles as $file) {
   	
	// get image sizes 
	list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
	$size = $file[sizetext];
	$iptc = iptcparse($info["APP13"]);
	// iptc  info
	$iptc = iptcparse($info["APP13"]);
	$title = $iptc['2#005'][0];
	$description = $iptc['2#120'][0];
	$description = str_replace("\r", "<br/>", $description);
	$description = addslashes($description);
	$keywords = $iptc['2#025'][0];
	$author = $iptc['2#080'][0];
	$copyright = $iptc['2#116'][0];
	
		array_push($photoarray, '<img src="'.$path.'/'.$file[name].'" width="'.$width.'" height="'.$height.'" alt="'.$title.'"  />');
		array_push($photoinfo, $title);
		array_push($photoinfo, $author);
		array_push($photoinfo, $copyright);
		array_push($photoinfo, $description);		
	}
	echo ' </div>
		   <div id="iptc_info">
  		    <div class="iptc_left"><br/><br/>
				Title <br/>
				Author <br/>
				Copyright <br/><br/>
				Description <br/><br/>
			</div>
			<div class="iptc_right"><br/><br/>
				'.$photoinfo[0].'<br/>
				'.$photoinfo[1].'<br/>
				'.$photoinfo[2].'<br/><br/>
				'.$photoinfo[3].'<br/><br/>
			</div>
		  </div>	
			';
}
 
function getthumbnailimages($path, $galleryName, $thumbnailpath) {
 
  $files = array();
   $fileNames = array();
   $i = 0;
   
   if (is_dir($path)) {
       if ($dh = opendir($path)) {
           while (($file = readdir($dh)) !== false) {
               if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
               $fullpath = $path . "/" . $file;
               $fkey = strtolower($file);
               while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
               $a = stat($fullpath);
               $files[$fkey]['size'] = $a['size'];
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
               $files[$fkey]['name'] = $file;
               $files[$fkey]['type'] = filetype($fullpath);
               $fileNames[$i++] = $fkey;
           }
           closedir($dh);
       } else die ("Cannot open directory:  $path");
   } else die ("Path is not a directory:  $path");
   sort($fileNames,SORT_STRING);
   $sortedFiles = array();
   $i = 0;
   $thumbs = array();
   foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
   $j=0;
   foreach ($sortedFiles as $file) {
   	
	// get image sizes 
	list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
	$size = $file['sizetext'];
	$iptc = iptcparse($info["APP13"]);
	// iptc  info
	$iptc = iptcparse($info["APP13"]);
	$title = $iptc['2#005'][0];
	$description = $iptc['2#120'][0];
	$description = str_replace("\r", "<br/>", $description);
	$description = addslashes($description);
	$keywords = $iptc['2#025'][0];
	$author = $iptc['2#080'][0];
	$copyright = $iptc['2#116'][0];
	
		array_push($thumbs, '<a href="#" onclick="getstarted('.$width.', '.$height.', \'imgloader\', '.$j.', \''.$j.'\', current_imgid);return false;"><img src="'.$thumbnailpath.'/'.$file['name'].'" alt="'.$title.'" title="'.$title.'" tooltitle="'.$title.'" class="toolTipImg" /></a>');
		echo $thumbs[$j];
		$j++;
	}
	
}

Open in new window

0
 
Hube02Commented:
Lines 177 and 179? What lines do they translate to in the code that you posted? I cannot find any reference to APP0 in the code that you posted.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
wilson1000Author Commented:
Sorry, was toying with the code before i posted.

The values are APP0 but they still return the same error.
0
 
wilson1000Author Commented:
I thinking the important error here is the Warning - this error is possibly causing the notices to the undefined indexes?

What do you think Hube?
0
 
wilson1000Author Commented:
Heres the code for the error message and with correct lines

<?php 
function getImages($path, $galleryName) {
 
  $files = array();
   $fileNames = array();
   $i = 0;
   
   if (is_dir($path)) {
       if ($dh = opendir($path)) {
           while (($file = readdir($dh)) !== false) {
               if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
               $fullpath = $path . "/" . $file;
               $fkey = strtolower($file);
               while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
               $a = stat($fullpath);
               $files[$fkey]['size'] = $a['size'];
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
               $files[$fkey]['name'] = $file;
               $files[$fkey]['type'] = filetype($fullpath);
               $fileNames[$i++] = $fkey;
           }
           closedir($dh);
       } else die ("Cannot open directory:  $path");
   } else die ("Path is not a directory:  $path");
   sort($fileNames,SORT_STRING);
   $sortedFiles = array();
   $i = 0;
   $photos = array();
   foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
   
   	
	echo "var $galleryName = new Array() \n";
 
   $j = 0;
   foreach ($sortedFiles as $file) {
   	
	// get image sizes 
	list($width, $height, $type, $attr) = getimagesize($path."/".$file[name], $info);
	$size = $file['sizetext'];
	$iptc = iptcparse($info["APP0"]);
	// iptc  info
	$iptc = iptcparse($info["APP0"]);
	$title = $iptc['2#005'][0];
	$description = $iptc['2#120'][0];
	$description = str_replace("\r", "<br/>", $description);
	$description = addslashes($description);
	$keywords = $iptc['2#025'][0];
	$author = $iptc['2#080'][0];
	$copyright = $iptc['2#116'][0];
		
		array_push($photos, $width);
		array_push($photos, $height);
		echo "$galleryName";echo"[".$j."]=['".$path."/".$file['name']."', '".$width."', '".$height."', '".$size."', '".$title."', '".$author."', '".$copyright."', '".$description."', '".$j."']\n";
		$j++;
	}
	echo "\n";
	echo "var currentwidth=".$photos[0].";\n";
	echo "var currentheight=".$photos[1].";";
	echo "\n";
 
}
 
 
function getfirstimage($path, $galleryName) {
 
  $files = array();
   $fileNames = array();
   $i = 0;
   
   if (is_dir($path)) {
       if ($dh = opendir($path)) {
           while (($file = readdir($dh)) !== false) {
               if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
               $fullpath = $path . "/" . $file;
               $fkey = strtolower($file);
               while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
               $a = stat($fullpath);
               $files[$fkey]['size'] = $a['size'];
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
               $files[$fkey]['name'] = $file;
               $files[$fkey]['type'] = filetype($fullpath);
               $fileNames[$i++] = $fkey;
           }
           closedir($dh);
       } else die ("Cannot open directory:  $path");
   } else die ("Path is not a directory:  $path");
   sort($fileNames,SORT_STRING);
   $sortedFiles = array();
   $i = 0;
   $photoarray = array();
   $photoinfo = array();
   foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
   echo'<div id="imgloader">';
   
   $j=0;
   foreach ($sortedFiles as $file) {
   	
	// get image sizes 
	list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
	$size = $file['sizetext'];
	$iptc = iptcparse($info["APP0"]);
	// iptc  info
	$iptc = iptcparse($info["APP0"]);
	$title = $iptc['2#005'][0];
	$description = $iptc['2#120'][0];
	$description = str_replace("\r", "<br/>", $description);
	$description = addslashes($description);
	$keywords = $iptc['2#025'][0];
	$author = $iptc['2#080'][0];
	$copyright = $iptc['2#116'][0];
	
		array_push($photoarray, '<img src="'.$path.'/'.$file['name'].'" width="'.$width.'" height="'.$height.'" alt="'.$title.'"  />');
		array_push($photoinfo, $title);
		array_push($photoinfo, $author);
		array_push($photoinfo, $copyright);
		array_push($photoinfo, $description);		
	}
	echo ' </div>
		   <div id="iptc_info">
  		    <div class="iptc_left"><br/><br/>
				Title <br/>
				Author <br/>
				Copyright <br/><br/>
				Description <br/><br/>
			</div>
			<div class="iptc_right"><br/><br/>
				'.$photoinfo[0].'<br/>
				'.$photoinfo[1].'<br/>
				'.$photoinfo[2].'<br/><br/>
				'.$photoinfo[3].'<br/><br/>
			</div>
		  </div>	
			';
}
 
function getthumbnailimages($path, $galleryName, $thumbnailpath) {
 
  $files = array();
   $fileNames = array();
   $i = 0;
   
   if (is_dir($path)) {
       if ($dh = opendir($path)) {
           while (($file = readdir($dh)) !== false) {
               if ($file == "." || $file == ".." || $file == ".DS_Store") continue;
               $fullpath = $path . "/" . $file;
               $fkey = strtolower($file);
               while (array_key_exists($fkey,$fileNames)) $fkey .= " ";
               $a = stat($fullpath);
               $files[$fkey]['size'] = $a['size'];
               if ($a['size'] == 0) $files[$fkey]['sizetext'] = "-";
               else if ($a['size'] > 1024) $files[$fkey]['sizetext'] = (ceil($a['size']/1024*100)/100) . " K";
               else if ($a['size'] > 1024*1024) $files[$fkey]['sizetext'] = (ceil($a['size']/(1024*1024)*100)/100) . " Mb";
               else $files[$fkey]['sizetext'] = $a['size'] . " bytes";
               $files[$fkey]['name'] = $file;
               $files[$fkey]['type'] = filetype($fullpath);
               $fileNames[$i++] = $fkey;
           }
           closedir($dh);
       } else die ("Cannot open directory:  $path");
   } else die ("Path is not a directory:  $path");
   sort($fileNames,SORT_STRING);
   $sortedFiles = array();
   $i = 0;
   $thumbs = array();
   foreach($fileNames as $f) $sortedFiles[$i++] = $files[$f];
   $j=0;
   foreach ($sortedFiles as $file) {
   	
	// get image sizes 
	list($width, $height, $type, $attr) = getimagesize("$path/$file[name]", $info);
	$size = $file['sizetext'];
	$iptc = iptcparse($info["APP0"]);
	// iptc  info
	$iptc = iptcparse($info["APP0"]);
	$title = $iptc['2#005'][0];
	$description = $iptc['2#120'][0];
	$description = str_replace("\r", "<br/>", $description);
	$description = addslashes($description);
	$keywords = $iptc['2#025'][0];
	$author = $iptc['2#080'][0];
	$copyright = $iptc['2#116'][0];
	
		array_push($thumbs, '<a href="#" onclick="getstarted('.$width.', '.$height.', \'imgloader\', '.$j.', \''.$j.'\', current_imgid);return false;"><img src="'.$thumbnailpath.'/'.$file['name'].'" alt="'.$title.'" title="'.$title.'" tooltitle="'.$title.'" class="toolTipImg" /></a>');
		echo $thumbs[$j];
		$j++;
	}
	
}
?>

Open in new window

0
 
wilson1000Author Commented:
Thanks Hube,

By changing that code to check isset, all the other variables in that array return as undefined. Is there a setting somewhere, maybe php.ini that should be enabled?
0
 
Hube02Commented:
Not that I know of, iptcparse() and iptcembed() do not require any special libraries or settings in php. Also getimagesize() does not need anything special.

you are using getimagesize("$path/$file[name]", $info); to get the IPTC data,

you can try print_r($info) to see if there is actually anything in there.
0
 
Hube02Commented:
You may also want to do a check to see if getimagesize() is getting anything at all.

getimagesize() will return false if the file is not a valid image file. I do not know if $info will have anything in it if the function returns false. I just had a problem myself where iptcembed() was corrupting the data stored in the image file and then from that point on the file did not act like a valid image.

Take a look at this question, it may help if you are running into the same problem if you are sure you're trying to access a valid image...

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24300155.html
0
 
wilson1000Author Commented:
hmmm,

Why is this line:

getimagesize("$path/$file[name]", $info);

encapsulating variables in quotes? is this ok? Trying print_r...
0
 
wilson1000Author Commented:
$info returns 1
0
 
Hube02Commented:
this works out the same as $path.'/'.$file['name']

when in double quotes php uses the value of the variable and not the literal $path.

It appears that $info is returning true, I have no idea what that means, but I suspect that the data is somehow being corrupted. $info should be an array if you are accessing a valid image file.
0
 
wilson1000Author Commented:
Turns out the problem was due to lack of support for IPTC in my PHP installation

 
0
 
Hube02Commented:
Interesting, I didn't know that IPTC support needed to be turned on.

How was it turned off?
0
 
wilson1000Author Commented:
I won't lie to your Hube, i have no idea?!

Is the support for IPTC built in?
0
 
Hube02Commented:
according to the php documentation iptcembed() and iprcparse() do not require the GD library. As far as I know this is part of php.

It could be disabled in the php.ini file, if you have access to this it would be in this setting:

disable_functions =

Other things that could cause it???

the file is protected in some way (readonly?) or the script does not have permission to write files. I'm not aware of a way do disable the overwriting of files, but have you tried to save the file to a different location that then original?

Does this e2 gallery provide any support. I'd be interested in discovering what you learn, simply because, as I said, I'm working on something extremely similar.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.