.
JavaScript
In this example, we use the input form field to upload an image. When you select an image on your computer, the image will be displayed on the page:
Document. getElementById ('upload-file '). addEventListener ('change', function () {var file; var destination = document. getElementById ('destination'); destination. innerHTML = ''; // loop the multiple objects selected by the user for (var x = 0,
Javascript uses fileReader to upload images and javascript to upload files
I will not explain the File API in detail here. We will use the File handle to read the File content. This is achieved through FileReader and through the FileReader interface, we can asynchronously lo
What methods and events does FileReader support? I will not introduce them here. if you are interested, go to the w3c official website to see the introduction of FileReader. here I will mainly introduce the common applications of FileReader, and fileReader. I will not explain the File API in detail here. we will use th
What methods and events does FileReader support? I will not introduce them here. If you are interested, go to the w3c official website to see the introduction of FileReader. Here I will mainly introduce the common applications of FileReader, and fileReader. I will not explain the File API in detail here. We will use th
File upload is now becoming more and more common, all social networking sites, media sites, such as Youku video, micro-blog, etc., all provide upload pictures, upload video and other functions. But in the past, web programmers know that uploading files with HTML forms can be a hassle, especially if you want to know some of the properties of a user's uploaded file, and you'll have to wait until it's uploaded.
Unknown things uploaded to the server, it is possible to create security problems, ther
at start of Read
OnProgress
Read in
Once a file begins to read, the result property of the instance is populated, regardless of success or failure. If the read fails, the value of result is null, otherwise it is the result of the read, and the vast majority of programs will fetch the value when the file is successfully read.Fr.onload = function () {This.result;};Example 1:3 , using JS of the
() supports two parameters. The first parameter is enabled when Promise is successful, and the second parameter is started when Promise fails. Use. catch () to achieve the same effect. In addition to better readability, the returned Promise object can also be passed at will to continue the chain call, which is quite imaginative.
Continue. then ()So we might as well concatenate more operations (if you want to write a resumable data transfer, let's talk about it later ):
Select All copies and put
()– Returns the data URL format of the file contents
These formats should initialize the send()方法前要初始化一个 same HTTP request as the XHR object before the file read operation. Again, you have to listen to the event before you start reading it load . The results read fromevent.target.result 获取。例如:
1234567891011
var reader = new FileReader();reader.onload = function(event) {var contents = event.target.result;console.log("File contents
Import java.io.*; public class Filereadersample {public static void main (String args[]) throws IOException {//Create an array that can hold 1024 characters Char Data[]=new char[1024]; Establish object Fr FileReader fr=new filereader ("C://java//donkey.txt"); Read the data into the character list, int num=fr.read (data); Converts a list of characters to a string Str=new string (data,0,num); Outp
About the file API here is not explained in detail, small partners to their own Niang it, we will use the file handle to read the file content, this is achieved through the FileReader, through the FileReader interface, we can asynchronously load the contents of the file into memory, give a JS variable.
Copy Code code as follows:
function getimgsrc (target, callback) {
if (window.
This article describes how to use FileReader to encode a file into Base64 and upload it via AJAX, including the PHP code that the backend decodes and stores the file data, for more information about how to use AJAX, you cannot directly upload files. Generally, you can create a new iframe to complete the form submission process in it to achieve asynchronous file upload.
This can achieve better browser compatibility, but the amount of code will be relat
Brief introduction
With the FileReader object, a Web application can asynchronously read the contents of a file (or raw data buffer) stored on a user's computer, and you can use a file object or a Blob object to specify the files or data that you want to work with. Where the file object can be from a user in a
More than one page, upload multiple pictures demo code
The above is the entire content of this article, I hope to learn
Double exclamation point in JavaScript !! Function example introduction, javascript example
!! It is generally used to forcibly convert the following expression to a boolean data (boolean), that is, it can only be true or false;
We often see this example:Copy codeThe Code is as follows:Var;Var B = !! A;A is undefined b
The example analyzes the working principle of the "JavaScript parser" in the browser, and the example analyzes the javascript
When the browser reads HTML files, it will wake up the so-called "JavaScript parser" only when it encounters the
After this code is run, the browser
Example of javascript Text Template usage and javascript example
This document describes how to use a javascript Text Template. Share it with you for your reference. The details are as follows:
This is a small function I wrote with reference to the Prism. js algorithm. There
JavaScript Example 1 (output element attribute) and javascript exampleI learned javascript For a long time ago, but I didn't think it was very useful. I did not expect the yarse to attack Gao fushuai in a few years. Javascript has become a universal cross-platform web langua
The example explains how to avoid javascript conflicts, and the example explains javascript
This article explains how to avoid conflicts in javascript.
[1] engineer A's writing function
var a = 1;var b = 2;alert(a+b);//3
[2] engineer B adds new function B
var a = 2;var b = 1
JavaScript code example for detecting the browser used by users, javascript example
Capability DetectionCheck the capabilities of a specific browser before writing the code. For example, before a script calls a function, it may need to check that the function has a down paym
JavaScript arguments object application example, javascript example
Arguments object
In function code, the special object arguments can be accessed without explicitly specifying the parameter names.
For example, in the sayHi () function, the first parameter is message. You c
JavaScript Example 7 (analog sending button) and javascript example
In the era of Selenium1.0, javascript is used, and similar measures should be used.
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.