Sending a file

The field for sending the file creates the form element as a text field for entering the file name, which is sent to the server. The field is created as follows.

<Form enctype = "multipart / form-data" method = "POST">
<Input type = "file" options>
</ Form>

The form parameters enctype = "multipart / form-data" are needed to correctly transfer the file. If you do not specify it, only the path to the file will be transferred. The additional parameters are the same as for the text field and are shown in Table. 1.

Table. 1. Field parameters for sending a file
Parameter Description
Name The name of the field. It is intended for the form handler to be able to identify this field.
Maxlength The maximum number of characters allowed in the text.
Size The width of the field.

Because the file size is usually large enough, you must use the POST method to send them to the server, as shown in Example 1.

Example 1. Creating a field to send a file

Valid HTML
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> Sending a file </ title>
</ Head>
<Body>

<Form action = "/ cgi-bin / handler.cgi" enctype = "multipart / form-data" method = "post">
<P> <b> Please specify the picture you want to add: </ b> </ p>
<P> <input type = "file" size = "30"> </ p>
<P> <input type = "submit" value = "Send"> </ p>
</ Form>

</ Body>
</ Html>

As a result, we get the following (Fig. 1).

Fig. 1

Fig. 1. Field type for sending a file

Copyright © www.htmlbook.ru