Created
February 10, 2024 15:18
-
-
Save anisur2805/beee64aec5831056f0d941c43fdb4c58 to your computer and use it in GitHub Desktop.
Upload image and preview image
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Upload and Preview Image</title> | |
</head> | |
<body> | |
<form action="" method="post" enctype="multipart/form-data"> | |
<input | |
type="file" | |
name="file" | |
accept="image/*" | |
onchange="previewFile(event)" | |
/> | |
<img src="" id="preview" style="max-width: 290px; height: auto;" /> | |
</form> | |
<script> | |
function previewFile(event) { | |
var input = event.target; | |
var reader = new FileReader(); | |
reader.onload = function(){ | |
var dataUrl = reader.result | |
var output = document.getElementById('preview'); | |
output.src = dataUrl; | |
console.log({dataUrl}) | |
} | |
reader.readAsDataURL(input.files[0]); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment