Forum Moderators: coopster

Message Too Old, No Replies

Check To See If Image Exists

How to overcome strange results

         

wealthyteddy

4:09 am on Mar 30, 2006 (gmt 0)

10+ Year Member



I've tried three different methods of checking whether an image on a server (sometimes my own, sometimes somebody else's) exists, and I'm not getting consistent results.

Method 1:

if (@fclose(@fopen("$burl", "r")))

Method 2:

if (file_exists($$burl))

Method 3:

if ($img = @GetImageSize("$burl"))

where $burl is an absolute URL to an image.

Methods 1 and 3 seem to return the same result, but Method 2 (as per the PHP Manual) always seems to return a "not found".

However, the strange thing is that all three methods sometimes return a "not found", even when the image does exist. For example, here's such a banner:

[is1.example.com...]

Is this because this banner is actually returned by some code on the the hosting server, and if so, is there any way around this (other than trying to copy the banner to my own server - although in this particular case, I can't do that either)?

(The reason I need it is that I have about 280 banners in rotation across several of my websites, and I have written a program that will check them all, switching them off or on as required, and emailing the results to me. If I can't find a consistent and accurate method of finding whether the image is currently working or not, I may have to go back to checking them all manually.)

Thanks,

Mark.

[edited by: coopster at 1:48 pm (utc) on Mar. 30, 2006]
[edit reason] generalized url TOS [webmasterworld.com] [/edit]

milanmk

4:46 am on Mar 30, 2006 (gmt 0)

10+ Year Member



You can try Server Header Check and see if image is broken or not.

[webmasterworld.com...]

[edited by: jatar_k at 5:39 am (utc) on Mar. 30, 2006]
[edit reason] fixed link [/edit]

wealthyteddy

11:12 am on Mar 30, 2006 (gmt 0)

10+ Year Member



Thanks for this information.

Are you aware of any way that I could use this code in my PHP program?

Thanks,

Mark.

sonjay

12:17 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



If that's an exact copy-and-paste from your actual code, Method 2 might work if you remove the extra $ from your variable: $$burl

jatar_k

3:20 pm on Mar 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld wealthyteddy,

method 2 shouldn't work for a url, though the manual says it should work with some wrappers in php5

I would go with method 1 or 3, probably 3 since that will also return false if it is not a valid image.