Created
July 9, 2016 21:00
-
-
Save flydev-fr/9b107d13c1cbe230e1d5c41afa6d18f2 to your computer and use it in GitHub Desktop.
Check mime type with finfo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [...] | |
$field = $this->modules->get("InputfieldFile"); // dummy field | |
$field->attr("name+id", 'photo'); | |
$form->add($field); | |
// DO NOT TRUST $_FILES['photo']['mime'] VALUE !! | |
// Check MIME Type by yourself. | |
$finfo = new \finfo(FILEINFO_MIME_TYPE); | |
$tof = $_FILES['photo']['tmp_name'][0]; // dummy var | |
if (false === $ext = array_search( | |
$finfo->file($tof), | |
array( | |
'jpg' => 'image/jpeg', | |
'png' => 'image/png', | |
'gif' => 'image/gif', | |
), | |
true | |
) | |
) { | |
// error | |
// INVALID FILE FORMAT | |
} | |
else { | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment