Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Preview Image while uploading
//<input onchange="previewFile('#logo_preview', '#logo')" id="logo" type="file" name="logo">
//<img id="logo_preview" src="">
function previewFile(preview, source) {
var preview = document.querySelector(preview);
var file = document.querySelector(source).files[0];
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
if (file) {
} else {
preview.src = "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment