HTML5 input:file Upload Type control

Source: Internet
Author: User

Original: HTML5 input:file upload Type control

HTML5 input:file Upload Type Control August 29, 2014 90,820 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, previous articles have also been said (see: JS Learning 32:html5 Drag-and-drop pictures batch Ajax no refresh progress upload). 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 datafor  (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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.