Mime type of .doc and .pdf

Hi all,

I am trying to check for mime types. The following extensions can be uploaded .txt, .doc and .pdf

To check for extensions I use

    $name = $_FILES['userfile']['name'];
   $extArray = array('.doc', '.txt', '.pdf');
   	$ext = strtolower(substr($name, -4));
   	echo $ext;
   	if (!in_array($ext, $extArray)) {
   	  return false;
   	  echo "Geen text";
   	} else {
   	echo "File is ".$ext;

Now for MIME type check I use

   $mimeArray = array('text/plain', 'application/pdf');
   	$mime = mime_content_type($_FILES['userfile']['tmp_name']);
   	if (!in_array($mime, $mimeArray)) {
   	  return false;
   	} else {
   	echo "Mime type is ".$mime;//test

Is application/pdf correct for .pdf? and will plain/text be correct for .doc??


PDF: application/pdf
Word: application/msword

well you could just check…

echo mime_content_type('test.pdf')." | ".mime_content_type('test.doc');

couldnt you?

plain/text is the MIME type for .txt files. For .doc you’ll need application/word or application/msword.

tx guys for your quick replies.

Indeed I have check it myself (what was I thinking), but like F4nat1c said I haven’t seen application/word so I added that to my array. My test.doc returned application/msword.


Hmmmm maybe theres a big list of common mime types somewhere… would be handy none the less…