title: Correct PHP way to check if external image exists?
body: <p>I know that there are at least 10 the same questions with answers but none of them seems to work for me flawlessly. I'm trying to check if internal or external image exists (is image URL valid?).</p>
  
  <ol>
  <li><p><code>fopen($url, 'r')</code> fails unless I use <code>@fopen()</code>:</p>
  
  <pre><code>Warning: fopen(http://example.com/img.jpg) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in file.php on line 21
  </code></pre></li>
  <li><p><code>getimagesize($img)</code> fails when image doesn't exist (PHP 5.3.8):</p>
  
  <pre><code>Warning: getimagesize() [function.getimagesize]: php_network_getaddresses: getaddrinfo failed
  </code></pre></li>
  <li>CURL fails because it isn't supported by some servers (although it's present mostly everywhere).</li>
  <li><code>fileExists()</code> fails because it doesn't work with external URLs and
  can't possibly check if we're dealing with image.</li>
  </ol>
  
  <p>Four methods that are the most common answers to such question are wrong. What would be the correct way to do that?</p>