How to use H5 to upload pictures
This time I will bring you how to use H5 to upload pictures and how to use H5 to upload pictures. Notes Yes Which ones, the following are practical cases, let’s take a look.
I worked on a project a few days ago, and one of the modules involved uploading images to the server. I took the time to sort it out today, and found that the more I sorted it out, the more knowledge points it involved. The following examples refer to Baidu’s image search.
Knowledge points: input file, base64, FileReader, canvas compression, blob, btoa encoding and atob decoding, FormData.
html dom node:
<input type="file">
A file can be selected by default. Multiple photos need to be uploaded. You can add the multiple="true" attribute. Generally use opacity:0; to hide the default style, and then rewrite its style.
1. Create object
var fileReader = new FileReader();
2. Determine whether the browser is compatible----it is not supported under ie8
if(window.FileReader)
3. Status constant
Constant name | Value | Description |
EMPTY | 0 | is the beginningReading file |
##LOADING | ##1File reading | |
2 | File Reading completed |
4. Attribute
Description | |||||||||||||||||||||||||||||||||
An error occurred while reading the file | |||||||||||||||||||||||||||||||||
The state of the current fileReader object is one of the above state constants | |||||||||||||||||||||||||||||||||
Read content |
Method name | Parameters | Description |
abort | None | Abort reading, calling in non-LOADING state will throw an exception |
##readAsArrayBuffer | blob/file | Read as an array, there is an ArrayBuffer object in the result for the read content |
readAsBinaryString | blob/file | Read as binary, there is a function to read the file in the result Raw binary |
readAsDataUrl | ##blob/fileread It is dataUrl, and there is a string in the data:url format in the result that represents the read content | |
blob/file, [encoding] | is read as text, and the string in the result represents the read content |
Description | |
Triggered on interrupt | |
Triggered when an error occurs | |
Triggered when the read is successful | |
Triggered when the read is completed (regardless of success) | |
Fires when reading starts | |
Triggered while reading |
The above is the detailed content of How to use H5 to upload pictures. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.
