php - something not working right

From Visual Basic to GNU C, this is the place to talk programming.

Moderators: SecretSquirrel, just brew it!

php - something not working right

Postposted on Wed May 20, 2009 3:44 pm

We are using something called "minimal Gallery" for our website. It's some open source php scripts to generate a photo gallery. It seems pretty neat. But something about the photo captioning does not seem to function correctly. The way it is supposed to work, according to the documentation, is this:

if there is a text file with the name of the current photo, get the caption from there,
else, get the caption from the iptc info in the photo

I've been looking through the code, and perhaps I have found what is wrong? Here is the code:
Code: Select all
function current_file_caption() {
   global $media_dir, $current_file, $current_file_uri;
   $temp_txt_URI = $media_dir.$current_file['category'].'/'.eregi_replace("[^[:alnum:]+]","_",strtolower(reset(explode('.',$current_file['file_name'])))).'.txt';
   $size = getimagesize($current_file_uri, $info);                        // extract iptc info from file   
   if (glob($temp_txt_URI)) {                                       // find if txt file w/ current media file name exists (PHP >= 4.3)
      @include($temp_txt_URI);                                    // include it in the page
   } else if (isset($info["APP13"])) {                                 // if not, check for IPTC info in the file
      $iptc = iptcparse($info["APP13"]);
      $desc_f_iptc = $iptc["2#120"][0];                              // that's the IPTC array element corresponding to "caption/abstract" in IPTC block
      echo("$desc_f_iptc");                                       // and echo it on the page
   }
}


and it looks to me as if $temp_txt_URI gets set with the iptc data before the code ever checks to see if there is a .txt file present. Am I right, or do I need to keep looking for the problem?

I don't know a damn thing about code, so, be gentle.
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH

Re: php - something not working right

Postposted on Wed May 20, 2009 4:09 pm

Here is the homepage and download link for minimal Gallery:
http://minimalgallery.net/home
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH

Re: php - something not working right

Postposted on Wed May 20, 2009 4:32 pm

Not having done php for awhile, and not having done it much then - take this with a grain of salt:

It looks like you're correct. What I would do is echo out each of those variables to make sure that they contain what you expect as a method of debugging this.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: php - something not working right

Postposted on Wed May 20, 2009 4:43 pm

steelcity_ballin wrote:Not having done php for awhile, and not having done it much then - take this with a grain of salt:

It looks like you're correct. What I would do is echo out each of those variables to make sure that they contain what you expect as a method of debugging this.

Sweet, that's what I tried to do, but I could not get the echo to work. Here is how I tried it:

Code: Select all
echo ("$current_file['file_name']");


and it busted the page.
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH

Re: php - something not working right

Postposted on Wed May 20, 2009 4:47 pm

well potentially that variable doesn't exist within the scope you used it... nevermind all that. Try something simple first. Try :

Code: Select all
echo ("hello world");


what you really want to try is echoing $temp_txt_URI
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: php - something not working right

Postposted on Wed May 20, 2009 4:49 pm

I also should have asked, but did you perform the correct steps on page 2 + of the manual? http://minimalgallery.net/_dl/mGallery_manual.pdf
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: php - something not working right

Postposted on Wed May 20, 2009 4:51 pm

Steel, thanks for the continuing help. Here's how I've done the echo calls:

Code: Select all
function current_file_caption() {
   global $media_dir, $current_file, $current_file_uri;
   $temp_txt_URI = $media_dir.$current_file['category'].'/'.eregi_replace("[^[:alnum:]+]","_",strtolower(reset(explode('.',$current_file['file_name'])))).'.txt';
   $size = getimagesize($current_file_uri, $info);                        // extract iptc info from file   
   if (glob($temp_txt_URI)) {                                       // find if txt file w/ current media file name exists (PHP >= 4.3)
      @include($temp_txt_URI);                                    // include it in the page
   } else if (isset($info["APP13"])) {                                 // if not, check for IPTC info in the file
      $iptc = iptcparse($info["APP13"]);
      $desc_f_iptc = $iptc["2#120"][0];                              // that's the IPTC array element corresponding to "caption/abstract" in IPTC block
      echo("$desc_f_iptc");                                       // and echo it on the page
   }
   echo ("Hello world");
   echo ("$temp_txt_URI");
}


They are not producing any output. They don't break the page, but they don't show any output either. Are they just in the wrong place?
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH

Re: php - something not working right

Postposted on Wed May 20, 2009 4:58 pm

Hmm... well the if hello world is not firing, then it would seem that the function is not being called. Can you email me the php page that this is on? I'll pm you my address.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: php - something not working right

Postposted on Wed May 20, 2009 5:07 pm

Just fired off an email.
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH

Re: php - something not working right

Postposted on Wed May 20, 2009 5:15 pm

Try adding these lines right under the $size variable, careful to go to the VERY end of a line before adding new lines, the comments could be pushed around.

echo('Hello World <br/> ');
echo('temp_text_URI is: '.$temp_txt_URI);

Note: the <br/> should add a new line in the page that will display these things, but I haven't touched php in a long time so it may require some escape characters to parse properly. If you get an error, delete the <br/>. Also, to be safe, make a backup of this file ( not that you couldn't just redownload it...)
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: php - something not working right

Postposted on Wed May 20, 2009 5:17 pm

Bah, time to make the evening commute. I'll check in later.
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH

Re: php - something not working right

Postposted on Wed May 20, 2009 5:18 pm

Can you also verify what version of PHP your server is running? According to the comments in the code, this captioning feature is supporting by version 4.3 and greater.
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11907
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: php - something not working right

Postposted on Wed May 20, 2009 7:04 pm

Yep:

Code: Select all
$ php -v
PHP 5.1.6 (cli) (built: May  9 2007 11:28:53)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
flip-mode
Gerbil Khan
Silver subscriber
 
 
Posts: 9084
Joined: Thu May 08, 2003 12:42 pm
Location: Cincinnati, OH


Return to Developer's Den

Who is online

Users browsing this forum: No registered users and 2 guests