input tag in HTML can be used to create a file input field within a form. This allows users to select and upload files from their local computer. Here’s an example of how to use the file input field:
<form action="/submit-form" method="post" enctype="multipart/form-data"> <label for="file">Select a file:</label> <input type="file" id="file" name="file"> <br> <button type="submit">Submit</button> </form>
In this example, the
input tag has a
type attribute set to
"file", which creates a file input field. The
id attribute is used to uniquely identify the field, and the
name attribute specifies the name of the field, which will be used to retrieve the uploaded file on the server.
form tag also has an
enctype attribute set to
"multipart/form-data". This is required when uploading files, as it specifies the type of encoding used for the data being submitted.
When the user selects a file using the file input field and submits the form, the file will be uploaded to the server along with the other form data. On the server side, you can access the uploaded file using the
name attribute of the file input field.