HTML5 input:file Upload Type Control August 29, 2014 200,687 views first, Input:file properties
The following are some of the more commonly used property values:
Accept: Represents the file MIME type that can be selected, multiple MIME types are separated by commas, and the commonly used MIME types are shown in the following table.
Multiple: Whether multiple files can be selected, the value of which is the virtual path of the first file when multiple files.
1. Accept
Only PNG and GIF images can be selected
<input id="fileId1" type="file" accept="image/png,image/gif" name="file" />
2, multiple
Multiple file uploads
<input id="fileId2" type="file" multiple="multiple" name="file" />
3. Common MIME Types
Suffix nameMimeName*.3gppAudio/3gpp,Video/3gpp*.AC3 Audio/Ac3*.ASF Allpication/Vnd.Ms-Asf*.Au audio/Basic*.CSS text/Css*.CSV text/Csv*.Doc Application/MSWord*.DOT Application/MSWord*.DTD application/Xml-Dtd*.DWG image/Vnd.Dwg*.DXF image/Vnd.Dxf*.GIF image/Gif*.HTM text/Html*.HTML text/Html*.JP2 image/Jp2*.JPE image/Jpeg*.JPEG image/Jpeg*.JPG image/Jpeg*.JS text/Javascript,Application/Javascript*.JSON application/Json*.MP2 Audio/Mpeg,Video/Mpeg*.MP3 Audio/Mpeg*.MP4 Audio/mp4,Video/mp4*.MPEG Video/Mpeg*.MPG video/Mpeg*.MPP Application/Vnd.Ms-Project*.OGG Application/Ogg,Audio/Ogg*.PDF application/Pdf*.PNG image/Png*.Pot application/Vnd.Ms-Powerpoint*.PPS Application/Vnd.Ms-Powerpoint*.PPT Application/Vnd.Ms-Powerpoint*.RTF Application/Rtf,Text/Rtf*.SVF image/Vnd.Svf*.TIF image/Tiff*.TIFF image/Tiff*.TXT text/Plain*.WDB Application/Vnd.Ms-Works*.WPS Application/Vnd.Ms-Works*.XHTML application/Xhtml+Xml*.XLC Application/Vnd.Ms-Excel*.XLM application/Vnd.Ms-Excel*.XLS application/Vnd.Ms-Excel*.XLT Application/Vnd.Ms-excel *./vnd.-excel *./xml, application /xml *./zip *./vnd.-officedocument.. Sheet
Second, style beautification
See blog: CSS Input[type=file] style beautification, input upload button beautify HTTP://WWW.HAOROOMS.COM/POST/CSS_INPUT_UPLOADMH
Third, Ajax upload files
When it comes to Ajax uploading files. When Ajax uploads, you need to get Input:file selected files (possibly multiple files) and get a list of their files as:
// input标签的files属性document.querySelector("#fileId").files// 返回的是一个文件列表数组
Get a list of the files and then iterate through the insert into the form data. That
Get the upload file Dom objectVarOfiles=Document.Queryselector("#fileId");Instantiate a form data objectVarFormData= New FormData();Traverse the list of picture files and insert them into the form data for (var I = 0 File; file = ofiles< Span class= "pun" >[i]; I++) { //file name, file object FormData append (file. Name, File /span>
Once you get the form data, you can upload it using Ajax post.
Instantiate an Ajax objectVarXhr= New XMLHttpRequest();xhr.= function () Span class= "pun" >{ Alert ( "upload success!) "}xhr. Open ( "POST" , " upload.php ", true); //send form data xhr.formdata
After uploading to the server, get to the list of files:
Array( [Jpg_jpg] = Array ( [Name] =Jpg.Jpg[Type] =Image/Jpeg[Tmp_name] =D:\xampp\tmp\phpa595.Tmp[Error] = 0 [Size] = 133363 ) [Png_png] = Array ( [Name] =Png.Png[Type] = = image/png [Tmp_name] + D:\xampp\tmp\phpa5a6 . tmp [error] = 0 [size] + = 1214628 ))
Loop through the array on the server to upload the file.
HTML5 input:file Upload Type control