title: Check if image is valid for showing
body: <p>I am trying to check if the link that the user have enter is a valid image. I tried to do that by using the function <code>getimagesize()</code>, and then if the function throws an error, then it's not a valid image.</p>
  
  <p>For some reason, the try-catch statement does not work. I tried to to use the function <code>file_exist()</code> as well, but when I enter a normal image link, it says it is not a valid image. How can I fix this?</p>
  
  <p>Attempt 1:</p>
  
  <pre><code>if ($link and file_exists($link))
  {
      echo "valid image!"
  }
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>$link = $_POST['link'];
  try
  {
      getimagesize($link);
  }
  catch(Exception $e)
  {
      echo "worng image! enter again link.";
  }
  </code></pre>