9.16. File Fields

File fields allow files to be attached to form data and sent along with the data to the handler. File fields have the following syntax:

<input type="file" name="name_of_field" size="display_size_of_field" />

The file field renders as a text box with a button that enables the user to browse for a file using their platform's file browser. Alternately, the user can manually type the full path and name of the file in the text box. Figure 9-5 shows an example of a file field.

Figure 9-5. Figure 9-5

However, to use this control in your forms, you must do the following:

  • Specify your form encoding as multipart, which allows the file to be attached to the rest of the data.

  • Use the POST, not the GET, method of form delivery. File information cannot be encapsulated using the GET method.

In other words, when using a file field, your <form> tag should resemble the following:

<form action="form_handler" method="post" enctype="form/multipart">

Get Web Standards Programmer's Reference: HTML, CSS, JavaScript®, Perl, Python®, and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.