0

I was saving photo file url for some flickr photos in my database for a while now. Lately i was getting the default image when the a file if delted or its permisions are changed. After a while i came to the conclusion that the photo still exists and the permisions didnt change, but the photo file url has changed.

For example:

Photo URL: http://www.flickr.com/photos/premnath/8127604491/

Photo file url saved by me a while ago : http://farm9.staticflickr.com/8336/8127604491_0eeb3b472d_z.jpg

Is there a fast way to check if a certain photo file url is still available. I want to implement a script that updates these url`s if they have changed in time that they are accessed.

I am using phpFlickr.

2 Answers2

1

When I try to access to the image http://farm9.staticflickr.com/8336/8127604491_0eeb3b472d_z.jpg from CURL, I am getting a HTTP Status 302 moved, and it points me to https://s.yimg.com/pw/images/photo_unavailable_z.gif (which is a standard image is unavailable image).

You need to find a way to capture the HTTP status and then act on it. 302 means it has moved. 200 means the image still exists.

Here is a sample code in PHP:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://farm9.staticflickr.com/8336/8127604491_0eeb3b472d_z.jpg");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_exec($ch);

$info = curl_getinfo($ch);

if ($info['http_code'] == 302) {
  echo "Image has moved";
}

curl_close($ch);
msound
  • 445
  • 3
  • 7
0

Thanks msound for the inspiration. I didn`t think of checking the headers. So i came up with a shorter, easier to understand version of the above.

$headerInfo = get_headers( $value['photo_file_url'], 1 );
if( $headerInfo[0] != "HTTP/1.1 200 OK" ){
   // Do something
}

The get_headers function returns something like this:

Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Tue, 08 Apr 2014 14:40:33 GMT
    [Content-Type] => image/jpeg
    [Content-Length] => 326978
    [Connection] => close
    [P3P] => policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    [Cache-Control] => max-age=315360000,public
    [Expires] => Sun, 10 Mar 2024 12:42:04 UTC
    [Last-Modified] => Wed, 25 Jul 2012 20:40:58 GMT
    [Accept-Ranges] => bytes
    [X-Cache] => Array
        (
            [0] => HIT from photocache814.flickr.bf1.yahoo.com
            [1] => HIT from cache414.flickr.ch1.yahoo.com
        )

    [X-Cache-Lookup] => Array
        (
            [0] => HIT from photocache814.flickr.bf1.yahoo.com:85
            [1] => HIT from cache414.flickr.ch1.yahoo.com:3128
        )

    [Age] => 1561078
    [Via] => 1.1 photocache814.flickr.bf1.yahoo.com:85 (squid/2.7.STABLE9), 1.1 cache414.flickr.ch1.yahoo.com:3128 (squid/2.7.STABLE9)
)