php - SOLVED: if_exists returning false negatives remote url -


ive been looking @ ages now, , decided time admit defeat , ask :d i'm designing world of warcraft guild website friend using wowarmoryapi. i'm doing members list, , not members (lower levels etc) have images yet. figured filter out ones returning false images , show "blankportrait.png" in place.

here code i'm using, (its on local site, no links i'm afraid)

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

any possible appreciated!

edit:: got in touch friend gave me solution using curl, here code used in end

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

file_exists should used on local or networked drives. in case, want see if string exists (or non-empty). can following:

$portrait = $member['character']['thumbnailurl']; $noportrait = "wp-content/themes/the-confederation/inc/images/blankportrait.png"; if (empty($portrait)) {   $portrait = $noportrait; } 

also, if you're in wordpress, may want set $noportrait include get_stylesheet_directory_uri().. such as:

$noportrait = get_stylesheet_directory_uri()."/inc/images/blankportrait.png"; 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -