Re: $_FILES
- From: Michael Fesser <netizen@xxxxxx>
- Date: Mon, 05 May 2008 21:54:48 +0200
..oO(Steve)
When uploading files i need to obtain the file type ( $_FILES['fupload']
['type'] ) and then check to make sure its a zip file. Now on one machine
the type is 'application/x-zip-compressed' and on another its
'application/zip'
I could send you a ZIP labeled as image/jpeg or vice versa ...
Is there anywhere or anyone that can tell me how many type there are for
one file type?
Since the MIME type is sent by the browser, you can't rely on it. It can
be faked or even completely empty. The definitely only way to make sure
that a file really is what it claims to be and what you expect is to
sniff a bit in its content.
One way for doing that is PHP's 'Fileinfo' extension, but it has to be
installed from the PECL archive. Another way on *nix machines would be
to use a system call to invoke the 'file' command, which is a standard
Unix tool and returns a lot of informations about a given file if it's
in a recognizable format.
If both methods fail, you could try to decompress it with PHP. If that
fails as well, you know at least that it wasn't a valid ZIP or GZ file.
HTH
Micha
.
- References:
- $_FILES
- From: Steve
- $_FILES
- Prev by Date: $_FILES
- Next by Date: Re: phpcounter fails after 2 years.
- Previous by thread: $_FILES
- Index(es):