HTML <input> Tag with 'type=file'

<form name="myForm" action="https://www.PuStudy.Com/html-solution/resources/html-forms-action.html">
	
<input type="file" name="myFile">

<button>Submit</button>
</form>

The above example demonstrates usage of the <input> element with the type attribute set to file (i.e. type="file").

The file value a list of selected files, each file consisting of a file name, a file type, and a file body (the contents of the file).

The accept Attribute

You can use the accept attribute to specify the file types that will be accepted. Any file type that is not specified will not be accepted.

It's best to specify both the MIME type as well as any extensions that might be used. Like this:

<form name="myForm2" action="https://www.PuStudy.Com/resources/html-forms-action.html">
	
<input type="file" name="myFile" accept=".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">

<button>Submit</button>
</form>

Specifies a comma-separated list of content types that the server accepts.

Possible values:

  • audio/*
  • video/*
  • image/*
  • [A valid MIME type, with no parameters]
  • [A string whose first character is a "." (U+002E) character] (for specifying a file extension)