I need to check a file's type on upload to make sure it's an image. What I'm thinking of doing is checking the MIME file type(from $_FILE
) and then checking that against the extension. Something like:
function checkType($file){
$ext = pathinfo($_FILES[$file]['name'], PATHINFO_EXTENSION);
$mime = $_FILES[$file]['type'];
if($mime == "image/jpg" || $mime == "image/jpeg"){
if($ext == "jpg" || $ext == "jpeg"){
return true;
} else{
return false;
}
}
if($mime == "image/gif"){
if($ext == "gif"){
return true;
} else{
return false;
}
}
if($mime == "image/png"){
if($ext == "png"){
return true;
} else{
return false;
}
}
}
Is this a good approach? Suggestions?
Also, how would I go about getting the width of the image before it's finally uploaded to the server?