Created
November 13, 2018 06:12
-
-
Save devfaysal/c01a1691b49f40bde26eefd97d66cb1e to your computer and use it in GitHub Desktop.
Preview Image while uploading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<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) { | |
reader.readAsDataURL(file); | |
} else { | |
preview.src = ""; | |
} | |
console.log(preview.src); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment