Jean Paul
Jean Paul

Reputation: 912

Getting field name of uploaded file

I'm writing a class to manage uploded files. Since the field name from the form the file is uploaded form can't be known now, here is what I'm doing:

        $field_name = array_keys($_FILES)[0];

Is that safe? Can I trust that the first key in $_FILES will always be the field name from the form? Thanks! ;)

Upvotes: 0

Views: 550

Answers (1)

Yorick
Yorick

Reputation: 793

If there is only the one <input type="file"... /> tag in your form yes. If there is more than one then the index 1 will be the second one etc.

Upvotes: 2

Related Questions