Pre-visualizar input type file
Publicado por Enrique (43 intervenciones) el 09/03/2020 22:06:03
Estoy intentando previsualizar el archivo antes de subirlo pero me aparece un error, si alguien me puede apoyar se los agradeceria mucho
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<form id="uploadForm" action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="imagen" id="imagen"/>
<input type="submit"/>
</form>
<div id="imagePreview">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
(function(){
function filePreview(input){
if(input.files && input.files[0]){
var reader = new FileReader();
reader.onload() = function(e){
$('#imagePreview').html("<img src='"+e.target.result+"'/>");
}
reader.readAsDataURL(input.files[0]);
}
}
$('#imagen').change(function(){
filePreview(this);
});
})();
</script>
Valora esta pregunta
0