Skip to content

Instantly share code, notes, and snippets.

@bbg
Last active January 21, 2020 22:32
Show Gist options
  • Save bbg/06bc056399d87b09243d to your computer and use it in GitHub Desktop.
Save bbg/06bc056399d87b09243d to your computer and use it in GitHub Desktop.
jQuery upload image take the base64 code
<!DOCTYPE html>
<html>
<head>
<metea charset="utf8">
<title></title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"></script>
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#falseinput').attr('src', e.target.result);
$('#base').val(e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
</head>
<body>
<h1>File Upload</h1>
<input id="fileinput" type="file" accept="image/gif, image/jpeg, image/png" onchange="readURL(this);" /> <br><br>
<textarea id="base"></textarea>
</body>
</html>
@codiiv
Copy link

codiiv commented May 12, 2018

Nifty, and works! Love if for fast Ajax uploads

@jhiver
Copy link

jhiver commented Apr 12, 2019

What is #falseinput for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment