<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