title: How To Check An Image Exists Or Not Through PHP?
body: <p>I want to check an image hosted on another site/server if that exists or not at the time of code running. For this purpose I am using JavaScript that is working fine with my desire that I am sharing below. But some browsers doesn't support JavaScript or some users are using blocking extension to block JavaScript so at that time my code does run.</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
   var url = 'http://www.example.com/example.jpg';
   var img = new Image();
   img.src = url;
   img.onload = function()
   {
   alert('Image Is Available')
   }
   img.onerror = function()
   {
   alert('Image Is Not Available')
   }
  &lt;/script&gt;
  </code></pre>
  
  <p>So now I want to do the same as in above code but by pure PHP. I don't want to use <code>fsockopen</code>, <code>file_get_contents</code>, <code>curl</code>, <code>get_headers</code> option to hit and check the server. I only want to hit image and check that like above. For this purpose I used the below code but its not working. Its showing <code>Image Is Not Available</code> even I am able to open image directly in browser. I found this code over internet.</p>
  
  <pre><code>&lt;?php
  $url = 'http://www.example.com/example.jpg';
  if (@GetImageSize($url)) {
  echo  "Image Is Available";
  } else {
  echo  "Image Is Not Available";
  }
  ?&gt;
  </code></pre>
  
  <p>So what the error is in this code? Can you mention and solve...???</p>
  
  <p><strong>Update</strong>: Please don't mention about image load time or size as I am hitting <code>favicon.ico</code> or other small size images on my target.</p>
  
  <p><strong>Important Problem</strong>: I check the above PHP code on another target and its working perfectly. But where I want to check the image is not working. Mine target didn't contain domain, Its an IP address like <code>hhtp://XX.XX.XX.XX:XXXX/example.jpg</code>. So the code is correct but my target is not replying to any external codes hit. Its displaying the image when I open the link directly in the browser. SO my this question contain answer also. I will ask another question about my new problem.</p>