Web forms can upload files to the server.

To add an attachment, you click the Browse button in the Web page to select a file on your computer.

Then, when you submit the form, your browser sends the file to the server along with the other form data.

You've already seen how to create a file select field at the start of this chapter:

<label for="fileSelectField">A file select field </label>
<input type="file" name="fileSelectField" id="fileSelectField" value="" />

In addition, a form containing a file select field must use the post method, and it must also have an enctype="multipart/form-data" attribute in its <form> tag, as follows:

<form action="form_handler.php" method="post" enctype="multipart/form-data">

This attribute ensures that the form data is encoded as mulitpart MIME data which is required for uploading binary data such as files.

You can have as many file select fields as you like within your form, allowing your users to upload multiple files at once.

Related Topic