For input in the form: it can be found directly by name, Document.form[0].input_file
Main code:
var inputfile = document.forms[0].input_file;
var files = inputfile.files; Gets the list of files
files[i].name
files[i].lastmodifieddate.tolocaledatestring ()
(files[i].size/1024). toFixed (2) + "KB"
Full example:
<! DOCTYPE html>
In addition, there are readasdataurl interfaces:
<form enctype= "Multipart/form-data" > <div class= "row Clearfix w840" > <div class= "R" > <input onclick= "CopyUrl2 ()" value= "copy" Name= "Res7" class= "tools_btn06" type= "button" >
; input onclick= "word.value=" "value=" Empty "name=" Res7 "class=" tools_btn06 "type=" button "> </div>
<div class= "span" style= "width:325px" > <a href= "javascript:;" class= "Input-file" > <input accept= "image/*" name= "Upimage" id= "Upload_file" "type=" File "value=" Click here to select the picture to convert to Base64 ">&nbs p; Click here to select the pictures to convert to Base64 </a> </div> <div class= "span" id= "Update_file_label" & gt;</div> </div> <div class= "row Clearfix tc" > <textarea id= "base64_output" Name= "
Word "style=" width:820px "></textarea> </div> <div class=" row Clearfix w840 "> <div class= "span" >
<input value= "restore generated Base64 encoded as Picture: class=" tools_btn02 "type=" button "onclick=" test_base64 (); " > </div> <div class= "span" style= "margin-left:10px" > <div class = "Strong Red" id= "Img_size" > </div> </div> </div> <div class= "row alert su ccess w840 "> </div> </form> <script type= "Text/javascript" > function $_ (ID) {
return document.getElementById (ID);
function Gen_base64 () {$_ (' base64_output '). Value = ';
$_ (' Img_size '). InnerHTML = ';
$_ (' Img_prev '). src = ';
var file = $_ (' Upload_file '). Files[0];
if (!/image\/\w+/.test (File.type)) {alert ("Make sure the file is an image type"); return false; } r = new FileReader ();
Local Preview r.onload = function () {$_ (' base64_output '). Value = R.result;
$_ (' Img_size '). InnerHTML = "Picture size:" + math.round (r.result.length/1024 * 1000)/1000 + "KB"; } r.readasdataurl (file);
BASE64} function Test_base64 () {$_ (' Img_prev '). src = ';
$_ (' Img_prev '). src = $_ (' Base64_output '). Value; } window.onload = function () {if (typeof (FileReader) = = ' undefined ') {a Lert ("Sorry, your browser does not support FileReader, please use modern browser operation.")
");
$_ (' Upload_file '). Disabled = true; } document.getElementById ("Upload_file"). onchange = function () {document.
getElementById ("Update_file_label"). InnerHTML = This.value;
Gen_base64 ();
};
</script>