Question

I want to check the mime-type of uploaded file in php and return true if it is allowed.

I have an array of some part of allowed mime-types like this:

$allowedMimes = array('images','word','pdf');

images is for jpg/png/gif and word is for doc/docx and pdf for pdf.

the mime-type of an uploaded docx file is for example:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

now i need to check it in array.i think i should use strpos but i don't know how use it with an array.

would you help me?

Was it helpful?

Solution

foreach( $allowedMimes as $mime ) {
   if( strpos( 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' , $mime ) ) {
    return true;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top