thumbimage.php errors when image missing

Thread Solved

Join Date: Mar 2005
Posts: 21
Reputation: Cobber is an unknown quantity at this point 
Solved Threads: 0
Cobber Cobber is offline Offline
Newbie Poster

thumbimage.php errors when image missing

 
0
  #1
Jul 27th, 2008
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: thumbimage.php errors when image missing

 
0
  #2
Jul 27th, 2008
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:
  1. if(!empty($pict_url))
Try changing you if statement from
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 21
Reputation: Cobber is an unknown quantity at this point 
Solved Threads: 0
Cobber Cobber is offline Offline
Newbie Poster

Re: thumbimage.php errors when image missing

 
0
  #3
Jul 27th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 21
Reputation: Cobber is an unknown quantity at this point 
Solved Threads: 0
Cobber Cobber is offline Offline
Newbie Poster

Re: thumbimage.php errors when image missing

 
0
  #4
Jul 27th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: thumbimage.php errors when image missing

 
0
  #5
Jul 27th, 2008
Maybe you should switch the script around alittle. Try the following.
  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.
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 21
Reputation: Cobber is an unknown quantity at this point 
Solved Threads: 0
Cobber Cobber is offline Offline
Newbie Poster

Re: thumbimage.php errors when image missing

 
0
  #6
Jul 28th, 2008
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: thumbimage.php errors when image missing

 
0
  #7
Jul 28th, 2008
Yeh I know I'm glad these forums exist too. I'm sorry that I couldn't be of more help.
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC