SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Code:
        $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
    Code:
       $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??

    tx

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    PDF: application/pdf
    Word: application/msword

  3. #3
    SitePoint Zealot _theworks's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well you could just check...

    PHP Code:
    echo mime_content_type('test.pdf')." | ".mime_content_type('test.doc'); 
    couldnt you?

  4. #4
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    plain/text is the MIME type for .txt files. For .doc you'll need application/word or application/msword.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  5. #5
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    tx

  6. #6
    SitePoint Zealot _theworks's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm maybe theres a big list of common mime types somewhere..... would be handy none the less...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •