MIMe types

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ktsirig
    New Member
    • Oct 2005
    • 11

    #1

    MIMe types

    Hi all!

    I have a question: I am constructing a form where the user can upload a file.
    I need however to verify that the file uploaded is a TEXT file.

    Is $_FILE['userfile']['type'] what I need? I am asking this because no matter if I upload a .txt or a .gif file, PHP says they are both $_FILE['userfile']['type']='text' and so, they are both uploaded on the server, whereas there should be only .txt file uploaded and not the .gif file.

    In general, how can I allow only text files to be uploaded?
    (Of course, i can't rely much on the extension I believe)..

    Thanx
  • ktsirig
    New Member
    • Oct 2005
    • 11

    #2
    MIMe types

    Hi!
    I am trying to validate that a file submitted through a form is a TEXT file.
    When I use $_FILES['userfile_PFAM']['type']=='text/plain' it works, but only for files with .txt extension.

    But the user may also have a file containing text data and may not have given the .txt extension (for example I found that application/octet-stream also reffers to TEXT files).
    Does anybody know which of the MIME types of PHP must I check for? The MIME types that reffer to TEXT I mean.

    Thanx!

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, ktsirig.

      Check out PHP's fileinfo extension.

      Comment

      Working...