Skip to content

Instantly share code, notes, and snippets.

@roman-m-work
Forked from bbg/example.html
Last active November 27, 2019 19:21
Show Gist options
  • Save roman-m-work/d898be553051c673aeb8c9fd881a377b to your computer and use it in GitHub Desktop.
Save roman-m-work/d898be553051c673aeb8c9fd881a377b to your computer and use it in GitHub Desktop.
jQuery upload image take the base64 code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<title>Online Base64 encoder</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment