title: How to catch invalid image when using PHP imagecreatefromstring
body: <p>i am using imagecreatefromstring and currently validate for proper image file format.</p>
  
  <p>So a link of:</p>
  
  <pre><code>swqkdwfibqwfwf
  </code></pre>
  
  <p>Wont work, because its not a valid file type. But i have just discovered this:</p>
  
  <pre><code>sibdlsibiwbifw.png
  </code></pre>
  
  <p>Will send without an error from my validation. I get this error for an image link that doesnt return and image:</p>
  
  <pre><code>Warning: file_get_contents(etwteet.png): failed to open stream: No such file or directory in /var/www/clients/client2/web3/web/process/addnewbuild.php on line 141
  
  Warning: imagecreatefromstring(): Empty string or invalid image in /var/www/clients/client2/web3/web/process/addnewbuild.php on line 141
  
  Warning: imagejpeg() expects parameter 1 to be resource, boolean given in /var/www/clients/client2/web3/web/process/addnewbuild.php on line 143
  </code></pre>
  
  <p>Is there a way i can catch this error so i can stop the code processing and also notify the user?</p>
  
  <p>Code used to get the URL:</p>
  
  <pre><code>$imagefile = image url;
  $resource = imagecreatefromstring(file_get_contents($imagefile));
  </code></pre>
  
  <p>Thanks. Craig.</p>