[Javascript] File to base64 upload

Table of Contents

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
body {
margin: 2em auto;
max-width: 600px;
form div {
margin-bottom: 0.5em;
form div label, form div input {
display: block;
margin-bottom: 0.3em;
base64 form upload
function readURL(input,oput)
input.style.display = "block";
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
input.src = e.target.result;
var src=e.target.result;
document.getElementById('imgshow'+oput).innerHTML='<img src="'+src+'" width="300px">';
<!--<form id="test" action="#" method="post">-->
<form class="form-horizontal" enctype="multipart/form-data">
<!-- Form Name -->
<input name="hinh1upload" id="hinh1upload" type="file" accept="image/*" onchange="readURL(this,'hinh1');" class="form-control">
<input type="hidden" name="hinh1" id="hinh1"/>
<div id="imgshowhinh1"></div>

Leave a Reply

Your email address will not be published. Required fields are marked *