Skip to content

Instantly share code, notes, and snippets.

@ezetojo
Last active September 20, 2020 02:24
Show Gist options
  • Save ezetojo/dcdbdb401e7879dd53d78da3a36fb256 to your computer and use it in GitHub Desktop.
Save ezetojo/dcdbdb401e7879dd53d78da3a36fb256 to your computer and use it in GitHub Desktop.
php file mime type validation before upload
<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$fileMime = finfo_file($finfo, $file["tmp_name"]);
finfo_close($finfo);
if($fileMime === "image/jpeg" || $fileMime === "image/png"){
// upload
}else{
echo "Wrong file format";
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment