How to get the image type in php
<p>I am trying to get the image type in the database but the below isn't working. How do I detect if the image is png, jpeg or gif?</p>

<pre><code>if(isset($_POST['submit'])) {
    $fileType = $_FILES['image']['type'];
    $tmpname = $_FILES['image']['tmp_name'];
    $fp = fopen($tmpname,'r');
    $data = fread($fp,filesize($tmpname));
    $data = addslashes($data);
    fclose($fp);

    $update = mysql_query("UPDATE avatar SET image1='$data',type='$fileType' WHERE username='$user'",$this-&gt;connect);
} else {
    echo "&lt;form enctype='multipart/form-data' action='http://www.example.com/cp/avatar' method='post'&gt;
        &lt;div id='afield1' &gt;Upload&lt;/div&gt;&lt;div id='afield2'&gt;&lt;input type='hidden' name='MAX_FILE_SIZE' value='102400' /&gt;&lt;input type='file' size='25' name='image' /&gt;&lt;/div&gt;
        &lt;div id='asubmit'&gt;&lt;input type='submit' name='submit' class='button' value='Save Changes' /&gt;&lt;/div&gt;
        &lt;/form&gt;";
}
</code></pre>
