943,917 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 695
  • PHP RSS
Jul 27th, 2008
0

thumbimage.php errors when image missing

Expand Post »
Hi,

I have spent hundreds of hours fixing errors with my phpauction GPL V2.51 script I bought. A lot have been cosmetic but this one is causing onscreen errors and making the page extremely slow to load.

To cut a long story short, if the thumbnail image a customer is linking to or has uploaded is not available for some reason, I get a "Division by Zero" error involving the file thumbimage.php

I have tried to fix it with no success. The database (I assume) knows what to look for and if it isn't there I get the onscreen errors.

Is there a way to get it to display the default "noimage.gif" picture instead of just spitting the dummy? I thought the coding did that at the bottom, but it doesn't.

This is extremely annoying because if, say a seller's Photobucket goes down - so does my website!

Here is the file code:

PHP Syntax (Toggle Plain Text)
  1. <?
  2. $pict_url = mysql_result($result, $i, "pict_url");
  3. $pict = "uploaded/$pict_url";
  4. $phu = intval(mysql_result( $result,$i,"photo_uploaded") &&($pict_url!=''));
  5. if ($pict_url != "") {
  6. if ( $phu) {$pict_url = $pict;
  7. }
  8. $f_size = @getimagesize($pict_url);
  9. $width = $f_size[0];
  10. $height = $f_size[1];
  11.  
  12. $x_ratio = $max / $width;
  13. $y_ratio = $max / $height;
  14.  
  15. if (($width <= $max) && ($height <= $max)) {
  16. $tn_width = $width;
  17. $tn_height = $height;
  18. }
  19.  
  20. else if (($x_ratio * $height) < $max) {
  21. $tn_height = ceil($x_ratio * $height);
  22. $tn_width = $max;
  23. }
  24.  
  25. else {
  26. $tn_width = ceil($y_ratio * $width);
  27. $tn_height = $max;
  28. }
  29.  
  30. $thumbnail = "<a href=\"item.php?id=$id\"><IMG SRC=\"$pict_url\" width=\"$tn_width\" height=\"$tn_height\" border=\"0\" alt=\"See more details for $title\">"."</a>";
  31.  
  32. $tplv[img] = "<a href=\"item.php?id=".$row[id]."\">"."<IMG SRC=\"$pict_url\" width=\"$tn_width\" height=\"$tn_height\" border=\"0\" alt=\"See more details for $title\">"."</a>";
  33.  
  34. $tplv .= "<a href=\"item.php?id=".$row[id]."\">"."<IMG SRC=\"$pict_url\" width=\"$tn_width\" height=\"$tn_height\" border=\"0\" alt=\"See more details for $title\">"."</a>";
  35.  
  36. }
  37.  
  38. else {
  39. $thumbnail = "<img src=\"images/nopicture.gif\" width=75>";
  40. $tplv[img] = "<img src=\"images/nopicture.gif\" width=75>";
  41. $tplv .= "<img src=\"images/nopicture.gif\" width=75>";
  42. }
  43. ?>

This is the only major problem I seem to have left and any help would be greatly appreciated.

Thanks in advance,

Graham
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Cobber is offline Offline
21 posts
since Mar 2005
Jul 27th, 2008
0

Re: thumbimage.php errors when image missing

HI, I don't know if this will help but I have a simlar php page in my project and I get a defaul image with the if statement like this:
PHP Syntax (Toggle Plain Text)
  1. if(!empty($pict_url))
Try changing you if statement from
PHP Syntax (Toggle Plain Text)
  1. if ($pict_url != "")
to the above if statement. It it doesn't wor4k let me know and I will try to figure something out.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Jul 27th, 2008
0

Re: thumbimage.php errors when image missing

Sorry Pomona,

That had no effect.

The problem is it's not empty, but the image it is looking for (and remebers) is not currently there.
Last edited by Cobber; Jul 27th, 2008 at 11:17 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Cobber is offline Offline
21 posts
since Mar 2005
Jul 27th, 2008
0

Re: thumbimage.php errors when image missing

I will narrow the problem down a little.

The uploaded images were lost yesterday while I was tweaking the website. That is not a real problem, as I simply uploaded dummy images.

The main worry is when a seller has simply linked to an image on another website. If that website goes down, I get the screen errors when I haven't actually done anything wrong.

The more images that are down, the longer the list of screen error messages, which you can imagine would really annoy visitors.

So what I really need is some way of going to the default nopicture.gif when an image link is down.

I hope that makes the problem better to understand and hopefully fix.

While I still have the chance to edit this post, my gut feeling is to find a workaround for when "pict_url" encounters a 404 (or whatever it's getting) error from the linked website, if that helps any.

Graham
Last edited by Cobber; Jul 27th, 2008 at 12:25 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Cobber is offline Offline
21 posts
since Mar 2005
Jul 27th, 2008
0

Re: thumbimage.php errors when image missing

Maybe you should switch the script around alittle. Try the following.
PHP Syntax (Toggle Plain Text)
  1. <?
  2. $pict_url = mysql_result($result, $i, "pict_url");
  3. $pict = "uploaded/$pict_url";
  4. $phu = intval(mysql_result( $result,$i,"photo_uploaded") &&($pict_url!=''));
  5. if ($pict_url != "") {
  6. $thumbnail = "<img src=\"images/nopicture.gif\" width=75>";
  7. $tplv[img] = "<img src=\"images/nopicture.gif\" width=75>";
  8. $tplv .= "<img src=\"images/nopicture.gif\" width=75>";
  9. }
  10. else {
  11.  
  12. if ( $phu) {$pict_url = $pict;
  13. }
  14. $f_size = @getimagesize($pict_url);
  15. $width = $f_size[0];
  16. $height = $f_size[1];
  17.  
  18. $x_ratio = $max / $width;
  19. $y_ratio = $max / $height;
  20.  
  21. if (($width <= $max) && ($height <= $max)) {
  22. $tn_width = $width;
  23. $tn_height = $height;
  24. }
  25.  
  26. else if (($x_ratio * $height) < $max) {
  27. $tn_height = ceil($x_ratio * $height);
  28. $tn_width = $max;
  29. }
  30.  
  31. else {
  32. $tn_width = ceil($y_ratio * $width);
  33. $tn_height = $max;
  34. }
  35.  
  36. $thumbnail = "<a href=\"item.php?id=$id\"><IMG SRC=\"$pict_url\" width=\"$tn_width\" height=\"$tn_height\" border=\"0\" alt=\"See more details for $title\">"."</a>";
  37.  
  38. $tplv[img] = "<a href=\"item.php?id=".$row[id]."\">"."<IMG SRC=\"$pict_url\" width=\"$tn_width\" height=\"$tn_height\" border=\"0\" alt=\"See more details for $title\">"."</a>";
  39.  
  40. $tplv .= "<a href=\"item.php?id=".$row[id]."\">"."<IMG SRC=\"$pict_url\" width=\"$tn_width\" height=\"$tn_height\" border=\"0\" alt=\"See more details for $title\">"."</a>";
  41. }
  42. ?>

I think maybe you were telling the script to do things backwards. I have caught myself on this several times. I hope this might help.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Jul 28th, 2008
0

Re: thumbimage.php errors when image missing

Hi Pomona,

Unfortunately that coding made ALL images go to nopicture.gif

A reply I got to the same post in a phpauction forum came up with a simple solution (which is usually the way) involving one line of code at the beginning of the file to simply disable the error messages:

PHP Syntax (Toggle Plain Text)
  1. error_reporting(0);

That fixed it and I also applied it to some other files that are used when clicking on the "More....." links:

view_more_ending.php

view_more_news.php

I appreciate the help you gave and the help of other forums. Without such places as these, us cowboys would have no hope of fixing things. It doesn't matter who solves the problem, it is the fact forums like these exist which is important.

Thanks,

Graham
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Cobber is offline Offline
21 posts
since Mar 2005
Jul 28th, 2008
0

Re: thumbimage.php errors when image missing

Yeh I know I'm glad these forums exist too. I'm sorry that I couldn't be of more help.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Correct Syntax
Next Thread in PHP Forum Timeline: displaying problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC