0
我一直在尋找這個多年,現在終於決定是時候承認失敗,並問:D 我目前正在設計一個朋友使用魔獸世界公會網站wowarmoryapi。然而,我目前正在做一個成員列表,並不是所有成員(較低級別等)都有圖像。 所以我想我會過濾掉那些返回錯誤圖像並在他們的位置顯示「blankportrait.png」。解決:if_exists返回false negatives遠程url
這裏是我正在使用的代碼,(其上的本地網站,所以沒有聯繫我怕)
$portrait = $member['character']['thumbnailURL'];
$noportrait = "wp-content/themes/the-confederation/inc/images/blankportrait.png";
if (file_exists($portrait)) {
$portrait;
} else {
$portrait = $noportrait;
};
?>
<div class="member">
<div class="memberportrait"><img src="<?php echo $portrait ?>"/></div>
任何幫助,可能將不勝感激!
編輯:: 了與誰給我用捲曲的溶液中的朋友聯絡,這裏是我到底
$noportrait = get_stylesheet_directory_uri()."/inc/images/blankportrait.png";
$h = curl_init($member['character']['thumbnailURL']);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($h);
$http_code = curl_getinfo($h, CURLINFO_HTTP_CODE);
if($http_code == 404)
{
$portrait = $noportrait;
}
else
{
$portrait = $member['character']['thumbnailURL'];
}
curl_close($h);
嗯,看起來像它應該工作,然而,由於某種原因崩潰的頁面... 「Aw Snap,出錯了......等等」 編輯:沒關係,解決了崩潰,但它仍然返回負面結果的錯誤鏈接:/ –
我只注意到我忘了提及它仍然返回一個值的事實,它只是一個404頁面。我希望幫助 –
什麼返回什麼? –