Re: Is it possible to test an uploaded file to check the type?
| From: | David Otton | Date: | Sun, 13 Jul 2003 17:43:29 +0000 |
| Subject: | Re: Is it possible to test an uploaded file to check the type? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155010@lists.php.net to get a copy of this message | ||
On Sun, 13 Jul 2003 13:32:00 -0400, you wrote:
>The upload process, already collects info on file types when you upload.
> From the manual ->
>
>> $_FILES['userfile']['type']
>>
>> The mime type of the file, if the browser provided this
>> information. An example would be "image/gif".
>>
>So, check $_FILES['userfile']['type'] against a set of allowed file
>types, and you're set...
A client-supplied value isn't going to be too useful - it can be spoofed, or
may not be present. (I believe a Windows browser would set the mime-type
based purely on the file extension, though I haven't tested this myself).
>Marek Kilimajer wrote:
>
>> If you have compiled php with --enable-mime-magic, you can use
>> mime_content_type()
This is the most-benefit least-effort choice if it's available, though I
believe that flag has been changed since 4.32[?]