Solved

e2 Gallery -  IPTC error

Posted on 2009-04-07
16
422 Views
Last Modified: 2013-12-12
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

0
Comment
Question by:wilson1000
  • 9
  • 7
16 Comments
 
LVL 4

Author Comment

by:wilson1000
ID: 24089009



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
 
LVL 18

Expert Comment

by:Hube02
ID: 24089164
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
 
LVL 4

Author Comment

by:wilson1000
ID: 24089263
Sorry, was toying with the code before i posted.

The values are APP0 but they still return the same error.
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24089284
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
 
LVL 4

Author Comment

by:wilson1000
ID: 24089311
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
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
ID: 24089422
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
 
LVL 4

Author Comment

by:wilson1000
ID: 24089637
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
 
LVL 18

Expert Comment

by:Hube02
ID: 24089760
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:Hube02
ID: 24089784
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
 
LVL 4

Author Comment

by:wilson1000
ID: 24089839
hmmm,

Why is this line:

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

encapsulating variables in quotes? is this ok? Trying print_r...
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24089855
$info returns 1
0
 
LVL 18

Expert Comment

by:Hube02
ID: 24089923
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
 
LVL 4

Author Comment

by:wilson1000
ID: 24140596
Turns out the problem was due to lack of support for IPTC in my PHP installation

 
0
 
LVL 18

Expert Comment

by:Hube02
ID: 24140715
Interesting, I didn't know that IPTC support needed to be turned on.

How was it turned off?
0
 
LVL 4

Author Comment

by:wilson1000
ID: 24141259
I won't lie to your Hube, i have no idea?!

Is the support for IPTC built in?
0
 
LVL 18

Expert Comment

by:Hube02
ID: 24143610
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now