HTML5 uploading and reading of local files

Source: Internet
Author: User

Window.onload=function () {
Read the file and get the object that uploaded the file tag
var f1=document.queryselector ("#f1");
var f2=document.queryselector ("#f2");
var f3=document.queryselector ("#f3");
F1.onchange=function () {
var fl1=this.files[0];//get the uploaded file
var freader=new filereader ();//Read the file, create an object that reads the file
Freader.readastext (FL1);//Read file
Freader.onload=function () {//start reading the file loaded events
var Result=freader.result;
Console.log (result);
var sty=document.createelement ("style");
var head=document.queryselector ("Head");
Head.appendchild (sty). Innerhtml=result;
}
}

  

F2.onchange=function () {
var fl2=this.files[0];
var freader=new filereader ();
Freader.readastext (FL2);
Freader.onload=function () {
var Resultjs=freader.result;
var scr=document.createelement (' script ');
var odiv=document.queryselector ("div");
Odiv.appendchild (SCR). Innerhtml=resultjs;
Console.log (RESULTJS);
}

}

F3.onchange=function () {
var fl3=this.files[0];
var freader=new filereader ();
Freader.Readasdataurl(fl3);//Read pictures
Freader.onload=function () {
var Resultimg=freader.result;
var oimg=document.createelement (' img ');
var odiv=document.queryselector ("div");
Odiv.appendchild (OIMG);
oimg.src=resultimg;
Console.log (OIMG);
}
}

}

HTML5 uploading and reading of local files

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.