Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getimagesize

Status
Not open for further replies.

degroat

Programmer
Sep 15, 2003
58
0
0
US
Below are two different errors I am getting when using this fuction. The 2nd one obviously is because the image was not found. What would be the reason for the first one? Both times I have gotten that error, the image that it was looking for should have been found.


Warning: getimagesize: Read error! in /home/afgart/public_html/thumbs.php on line 12


Warning: getimagesize: Unable to open 'prints/CLI/thumbs/C1639.jpg' for reading. in /home/afgart/public_html/thumbs.php on line 12
 
No... it says the read error is 'in' the PHP file.
 
Really.. the difference in these really isn't all that important and isn't really what is causing my problem.

Easiest way to explain this is just to show it...

go to in the search box, type "cindy ritts" and hit search

Under each of the thumbs you'll see 'FETemp' and then a value... if that value is = 1, then the system found the image it was supposed to be displaying. As you can see, the 2nd image has a FETemp = 1 but the image is not displaying. So, since FETemp=1, it tries to execute getimagesize and then throws the error.

What I cannot figure out is why that FETemp = 1 for the 2nd image. I did read somewhere that you may have to clear the cache if you're looking for the same filename (and in this case it is looking for the same file... 23001.jpg... just in a different folder), so I used clearstatcache() but it doesn't seem to be working.
 
Just found another place where this is happening... if you search for 'blakeway' and go to the 11th page (by clicking Next 10) you'll see the same thing... FETemps = 1 when the image doesn't exist.
 
$fetemp = file_exists("prints/.../imgfilename.jpg");
 
What's the source for your images? Have you tried opening the file in some image editor and resaving it? Every so often I come across JPEGs that are viewable by some but not all software and that seem to have something squirrely in the image encoding in the file.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
The problem only occurs when the images don't exist... file_exists returns TRUE when it should return FALSE.

What I need to do is limit the size of the image if it larger than a certain size. So, to do that I'm using what you showed me before... getimagesize. But, if that doesn't find the image it throws up an error and that in turn throws off the formatting of the page. So, to avoid that, I'm trying to use file_exists. If it does, then I check the size. If it does not, I want an email to be sent to me to let me know the image is broken...

Code:
$fetemp = file_exists("prints/$pub/thumbs/$pubid.jpg");
						
if($fetemp == 1)
{	
   list($width1, $height1, $type1, $attr1) = getimagesize("prints/$pub/thumbs/$pubid.jpg");
   if($width1 > 160) { $wblock = "width=160 "; }
   else {$wblock = " ";}
   if($height1 > 108) { $hblock = "height=108 "; }
   else {$hblock = " ";}
}
else
{
   $msg = "Publisher: $pub\nItem #: $pubid\nPrint ID: $print_id";
   $to = "XXXXXX";
   $subject = "AFGArt.com Missing Thumbnail";
   $mailheaders = &quot;From: XXXX <> \n&quot;;
   $mailheaders .= &quot;Reply-To: $email\n\n&quot;;
   mail($to, $subject, $msg, $mailheaders);
}
 
So in other words, despite the title of this thread, the problem is not with getimagesize(), but rather with file_exists().

I want you to make a couple of changes to your script. These changes should not change the behavior of your script, but let's eliminate as many possible factors at once.

First, I notice you're constructing the filename twice and that you are using implicit string concatentation. Let's construct the filename once and put the filename in a variable.

Also, you're comparing the return of file_exists() to 1. Since file_exists() returns a variable of type BOOL, you should be comparing it to TRUE instead. And let's use the &quot;===&quot; operator instead of the &quot;==&quot; operator.

The first part of the script snippet you posted would then read:

Code:
$fetemp_filename= 'prints/' . $pub . '/thumbs/' . $pubid . '.jpg';
$fetemp = file_exists($fetemp_filename);
                        
if($fetemp === TRUE)
{    
   list($width1, $height1, $type1, $attr1) = getimagesize($fetemp_filename);


Does any of this change the behavior of the script?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
After banging my head on a brick wall numerous times, I figured out the problem... the reason why file_exists was finding the file was because the file technically did exist... but the file was 0 bytes... so it didn't load up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top