簡體   English   中英

檢查Flickr照片文件網址是否仍然可用

[英]Check if Flickr photo file url still available

我暫時在數據庫中保存了一些flickr照片的照片文件URL。 最近,當文件被刪除或s permisions are changed. After a while i came to the conclusion that the photo still exists and the permisions didn時,我得到了默認圖像s permisions are changed. After a while i came to the conclusion that the photo still exists and the permisions didn s permisions are changed. After a while i came to the conclusion that the photo still exists and the permisions didn改變,但是照片文件的URL已更改。

例如:

圖片網址: http : //www.flickr.com/photos/premnath/8127604491/

我之前保存的照片文件網址: http : //farm9.staticflickr.com/8336/8127604491_0eeb3b472d_z.jpg

有沒有一種快速的方法來檢查某個照片文件的網址是否仍然可用。 我想實現一個腳本來更新這些url,如果它們在訪問時隨時間變化了。

我正在使用phpFlickr。

當我嘗試從CURL訪問圖像http://farm9.staticflickr.com/8336/8127604491_0eeb3b472d_z.jpg時,我正在移動HTTP狀態302,它將我指向https://s.yimg.com/ pw / images / photo_unavailable_z.gif (這是標准圖像,是不可用的圖像)。

您需要找到一種捕獲HTTP狀態並對其采取行動的方法。 302表示它已移動。 200表示圖像仍然存在。

這是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的啟發。 我沒想到要檢查標題。 所以我想出了一個簡短易懂的上述版本。

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

get_headers函數返回以下內容:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM