PHP: Detecting file extension from: filename.jpg
<p>Yes as the title says:</p>

<p>How can i detect an file extension? $_POST['fname']; is where i have the filename stored e.g asddsa.jpg</p>

<p>So how can i check if .jpg then ... if .png then ... ?</p>

<pre><code>    $src = "images/status/photo/".$_POST['fname'];
    $parts=pathinfo($src);
if($parts['extension'] == "jpg"){
    $img_r = imagecreatefromjpeg($src);
}elseif($parts['extension'] == "png"){
    $img_r = imagecreatefrompng($src);
}elseif($parts['extension'] == "gif"){
    $img_r = imagecreatefromgif($src);
}
</code></pre>

<p>tried this too without any success:</p>

<pre><code>    $ext= pathinfo($src, PATHINFO_EXTENSION);
if($ext == "jpg"){
    $img_r = imagecreatefromjpeg($src);
}elseif($ext == "png"){
    $img_r = imagecreatefrompng($src);
}elseif($ext == "gif"){
    $img_r = imagecreatefromgif($src);
}
</code></pre>
