phpurlflickrphpflickr

Check if Flickr photo file url still available


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.


Solution

  • 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);