Skip to content

Instantly share code, notes, and snippets.

@pradeeprjth
Created February 9, 2022 06:21
Show Gist options
  • Save pradeeprjth/07c036a2c7e39c0eb1efd832bf8fc762 to your computer and use it in GitHub Desktop.
Save pradeeprjth/07c036a2c7e39c0eb1efd832bf8fc762 to your computer and use it in GitHub Desktop.
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imageResult')
.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
$(function() {
$('#upload').on('change', function() {
readURL(input);
});
});
/* ==========================================
SHOW UPLOADED IMAGE NAME
* ========================================== */
var input = document.getElementById('upload');
var infoArea = document.getElementById('upload-label');
input.addEventListener('change', showFileName);
function showFileName(event) {
var input = event.srcElement;
var fileName = input.files[0].name;
infoArea.textContent = 'File name: ' + fileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment