I have a problem with the following code, what I want to do is that if the image is larger than 3.67 MB, I warn the user that it is very large, and that he does not select the image, since when he gives the alert the user the image is still selected.
<!DOCTYPE html>
<html lang="es-ar">
<head>
<meta charset="utf-8" />
<title>Tamaño archivo</title>
</head>
<body>
<form action="#">
<input type="file" id="archivos" accept="image/*" name="archivos[]"/>
</form>
<script>
function archivoSeleccionado(evt) {
if(window.File && window.FileReader && window.FileList && window.Blob){
var image = this.files[0].size;
if(image >= 3856819){
alert("La imagen es muy grande, El tamaño maximo es de 3.67 MB");
}else{
alert("La imagen tiene el tamaño adecuado");
}
}
}
document.getElementById('archivos').addEventListener('change', archivoSeleccionado, false);
</script>
</body>
</html>