Okay, so I got PHP handling file uploads with no trouble.  Then I got the bright idea of trying to make sure that users are uploading files of the expected type.  If we ask for Word document, then we should check to make sure what they upload is a word document.  If we ask for a Word Perfect, you get the idea.
This works all fine and dandy with PC browsers.  ( Provided their files have etensions on them. ) But on the Mac side things are tricky.
First off the Mac files have to have extensions before there's even a hope of determining MIME type.  And it turns out the Explorer declares the MIME type to be application/x-macbinary no matter what the file actually is.
Has anyone come up with a good way to verify that files are at least the correct type when they get uploaded?
    • [deleted]

    Technically you can only be sure of the filetype by opening the file and looking inside.

    If the browser takes the mimetype from the file's extention, then you might as well do the same, because the mimetype depends on that anyway :-)

      Since PHP doesn't have a function to peek at the header of a file, like mod_mime_magic for Apache, I take it I'll have to write one?
      Or has someone already written one?
        • [deleted]

        Yup, you'd have to write one.
        not amazingly difficult actually.

        But, you can only read a file once it's uploaded,
        so it would be a bit of a bummer for the uploader to upload a file and then hear that he's not allowed to upload that type of file.

          9 months later

          any word on this? I'm looking for the same thing. For now, i'm going to kick back any files without extensions.

            2 months later

            has anyone found a workaround for this? I'm not really a php coder but I have the upload thing working to an extent, but certain filetypes fail when uploading from a mac, and unfortunately they will be my target audience for the file upload. It even fails with stuffit files, which surprises me. It only seems to work with application/octet stream and text/plain files.

              I decided to kick the file back if I couldn't detect a file type or a "."

              The error message just says that the file must have an extension. Works well so far.

                3 months later

                Try PHP's headers_sent() function....

                  Write a Reply...