Home  >  Article  >  Web Front-end  >  How to implement file upload function in html5

How to implement file upload function in html5

清浅
清浅Original
2018-11-16 12:42:0610935browse

This article will share a case with you, using HTML5 to implement the file upload function. It has certain reference value and I hope it will be helpful to everyone.

Some of the new API methods in html5 allow us to implement some The function is simpler and more dynamic effects can be achieved. Next, the implementation of the file upload function will be introduced in detail

Knowledge points used in case implementation

(1) Multiple is a new attribute in HTML5. It is mainly used for uploading multiple value files. It stipulates that multiple values ​​can be selected for the input field. It is generally shared with email and file in the input attribute.

(2) The querySelector() method is mainly Used to return the first element in the document that matches the specified selector. If you want to return all elements, you can use the querySelectorAll() method instead.

(3) The FileReader object allows applications to asynchronously read the contents of files stored on the computer, using File or Blob objects to specify the files or data to be read. The File object can be a FileList object returned after selecting a file from the d5fd7aea971a85678ba271703566ebfd element

(4) readAsDataURL: Display the read image file directly on the web page to achieve a preview effect

Code display





文件读取



Effect display

Before unselected

Image 6.jpg

After selecting

Image 7.jpg

#Summary: The above is the content of this article. I hope to help you learn how to use HTML5 to upload files.

The above is the detailed content of How to implement file upload function in html5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]