PHP: What is the origin of a type index in $ _FILES?

To check for valid mime types when downloading files, I usually rely on the extension fileinfo, but since this extension or magic database is not always available. I use the type indexassociated with each file on $_FILESsuperglobal.

So my question is: where does this index come from? I suspect that this either comes from the browser (and, if possible, it can be faked), or, most likely, from the web server (or PHP) - and if so: is it just an extension for displaying a MIME type or is it real thing?

+3
source share
3 answers

MIME , , . , , .

+5

, @BoldClock .

-, , 100% , Magic Number .

, .

, , 4/8/16 .

PDF "% PDF" (hex 25 50 44 46).

, : Microsoft Office PPT/DOC/XLS -, .

.

+1

It is defined by the client when it creates a POST request. Files can only be present with the body multipart / form-data , which looks like this:

--BoUnDaRy02984
Content-Disposition: form-data; name="textfield1"
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Joe owes =80100.
 --BoUnDaRy02984
Content-Disposition: form-data; name="file2"; filename="C:\tmp\file.doc"
Content-Type: application/ms-word
Content-Transfer-Encoding: base64
Content-Length: 32

VGhpcyB3b3VsZCBiZSB0aGUgdGV4dAo=
 --BoUnDaRy02984

PHP does not interpret all possible multipart / options, but detects file downloads using the attribute filename=and uses the field Content-Type:verbatim for $ _FILES [*] [type].

+1
source

Source: https://habr.com/ru/post/1792858/


All Articles