0

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

Tofig Hasanov
  • 3,303
  • 10
  • 51
  • 81
  • Why not try it yourself? – Musa Sep 06 '12 at 04:28
  • I've seen some posts saying that this way I cannot get data from $_POST. For ex: http://stackoverflow.com/questions/1075513/php-parsing-multipart-form-data – Tofig Hasanov Sep 06 '12 at 04:31
  • 1
    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 Sep 06 '12 at 04:32

2 Answers2

1

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

Community
  • 1
  • 1
Kao
  • 2,242
  • 3
  • 22
  • 31
1

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.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335