title: Check image type in php
body: <p>I am getting a problem to check wheather image is png,gif,jpg,jpeg. i tried using <strong>getimagesize(path to file)</strong> but it needs full path of image as i just have only image name that is <strong>image1.jpg</strong>. I want to check file type that is png,gif,jpg,jpeg before uploading it. I want a code to check type before uploading it to the directory. <strong>getimagesize(path to file)</strong> gives me waring that <strong>Failed to open stream</strong> becaus efile is not in directory, it is not uplaoded yet. I didnt find any thing that works for me. Can anybody here help me out of this problem.  Here is my code:</p>
  
  <pre><code>list(image_width, image_height, image_type) = getimagesize("image1.jpg");
  switch ($source_image_type)
  {
      case IMAGETYPE_GIF:
          //some code here
      break;
      case IMAGETYPE_JPEG:
          //some code here
      break;
      case IMAGETYPE_PNG:
          //some code here
      break;
  }
  </code></pre>
  
  <p>This code gives me warning that Failed to open stream.</p>