Skip to content

Instantly share code, notes, and snippets.

@flydev-fr
Created July 9, 2016 21:00
Show Gist options
  • Save flydev-fr/9b107d13c1cbe230e1d5c41afa6d18f2 to your computer and use it in GitHub Desktop.
Save flydev-fr/9b107d13c1cbe230e1d5c41afa6d18f2 to your computer and use it in GitHub Desktop.
Check mime type with finfo.
// [...]
$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