HTML image upload

Source: Internet
Author: User

<script type= "Text/javascript" >
var Result=document.getelementbyid ("result");
var File=document.getelementbyid ("file");

Determine if the browser supports the FileReader interface
if (typeof FileReader = = ' undefined ') {
Result. Innerhtml= "<p> your browser does not support FileReader interface! </p> ";
Make the selection control not operational
File.setattribute ("Disabled", "disabled");
}

function Readasdataurl () {
Verify that the image file is
var file = document.getElementById ("file"). Files[0];
if (!/image\/\w+/.test (File.type)) {
Alert ("See Clearly, this needs a picture!") ");
return false;
}
var reader = new FileReader ();
Read the file into the page as a data URL
Reader.readasdataurl (file);
Reader.onload=function (e) {
var Result=document.getelementbyid ("result");
Show Files
Result.innerhtml= ' ';
}
}

function readasbinarystring () {
var file = document.getElementById ("file"). Files[0];
var reader = new FileReader ();
Read the file into the page in binary form
reader.readasbinarystring (file);
Reader.onload=function (f) {
var Result=document.getelementbyid ("result");
Show Files
Result.innerhtml=this.result;
}
}

function Readastext () {
var file = document.getElementById ("file"). Files[0];
var reader = new FileReader ();
Read the file into the page as text
Reader.readastext (file);
Reader.onload=function (f) {
var Result=document.getelementbyid ("result");
Show Files
Result.innerhtml=this.result;
}
}
</script>
<p>
<label> Please select a file:</label>
<input type= "File" id= "file"/>
<input type= "button" value= "read image" onclick= "Readasdataurl ()"/>
<input type= "button" value= "read binary data" onclick= "readasbinarystring ()"/>
<input type= "button" value= "read text file" onclick= "Readastext ()"/>
</p>
<div id= "Result" name= "result" ></div>

HTML image upload

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.