Skip to content

Instantly share code, notes, and snippets.

@manuelcanga
Created January 7, 2022 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelcanga/c615def89c2333b5ed924e5ca66bb5c3 to your computer and use it in GitHub Desktop.
Save manuelcanga/c615def89c2333b5ed924e5ca66bb5c3 to your computer and use it in GitHub Desktop.
Subida de imágenes con previo
<input type='file' onchange="previewImage(this, 'preview-image');" />
<img id="preview-image" src="http://placehold.it/300" alt="image preview" />
function previewImage(input, container) {
if( input.files.length < 1) {
return ;
}
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById(container).src = e.target.result;
};
reader.readAsDataURL(input.files[0]);
}
img#preview-image{
max-width:300px;
}
input[type=file]{
padding:10px;
background:#2d2d2d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment