Skip to content

Instantly share code, notes, and snippets.

@noondreams
Created February 17, 2014 12:43
Show Gist options
  • Save noondreams/9049886 to your computer and use it in GitHub Desktop.
Save noondreams/9049886 to your computer and use it in GitHub Desktop.
public function mimeIsAmong( $error_msg )
{
$r_conditions = array(
"image/png" ,
"image/jpg" ,
"image/jpeg" ,
"image/gif" ,
"application/pdf" ,
"application/msword" ,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" );
$oFileInfo = new finfo ( FILEINFO_MIME_TYPE ) ;
$sMimeType = $oFileInfo -> file ( "path/to/your/file") ;
if ( ! in_array ( $sMimeType , $ar_conditions ) )
{
throw new \Exception("Someone is trying to upload an illegal file. Warn him!!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment