title: Check if an image exists
body: <p>I have foreach loop that looks like this:</p>
  
  <pre><code>foreach($wdata-&gt;query-&gt;pages-&gt;$wpageid-&gt;images as $iimages)
  {
  $name = $iimages-&gt;title;
  $filename = str_replace(" ", "_",$name);
  $filename = str_replace("File:","",$filename);
  $digest = md5($filename);
  $folder = $digest[0].'/'.$digest[0].$digest[1].'/'. $filename;
  $url = 'http://upload.wikimedia.org/wikipedia/commons/'.$folder;
  echo "&lt;img style='height:100px;' src='$url'&gt;";
  }
  </code></pre>
  
  <p>It displayes images from a returned json array ($wdata)
  However, some images have been moved, or don't exist anymore, and I get cracked images, does anyone know how to check if an image is real, exists and can be viewed before it is echoed</p>