0
votes

I am new to PHP and HTML, and have trouble understanding the enctype attribute of the form when using POST. In all examples of File Upload using PHP, it is written that I should set enctype as multipart/form-data (which, as far as I understand, is used for files). However in all these examples, the only input on the form is file input.

My question is, what if I want to have form with mixed inputs? Particularly, both text and file. Then, if I set enctype to multipart/form-data, will I still be able to access both files and text from PHP using $_FILES and $_POST?

Thank you

2
Why not try it yourself? - Musa
I've seen some posts saying that this way I cannot get data from $_POST. For ex: stackoverflow.com/questions/1075513/… - Tofig Hasanov
enctype is used when your form contains file input if your form do not have file input there is no need of it. You will get values in $_FILES only if enctype is added in your form. Don't Worry about $_POST you can access your all values using it apart from file input. - gaurang171

2 Answers

1
votes

It basically means, add the $_FILE array to the request. For more information, read this question
What does enctype='multipart/form-data' mean?

1
votes

Use multipart/form-data.

It converts each piece of data to a part in a multi-part MIME request (and then does some specific encoding of each part). It isn't just for files, and if you are using PHP then $_POST will be populated normally.

The alternative (application/x-www-form-urlencoded) basically builds a query string. For a POST request it makes that query string the request body. This format doesn't have any provision for encoding files.