Quero obter o tamanho do arquivo em MB se o valor for> 1024 ou em KB se <1024
$(document).ready(function() {
$('input[type="file"]').change(function(event) {
var _size = this.files[0].size + 'mb';
alert(_size);
});
});
<input type="file">
Encontre o código atualizado abaixo. Veja o exemplo de trabalho aqui , Cheers!
$(document).ready(function() {
$('input[type="file"]').change(function(event) {
var _size = this.files[0].size;
var fSExt = new Array('Bytes', 'KB', 'MB', 'GB'),
i=0;while(_size>900){_size/=1024;i++;}
var exactSize = (Math.round(_size*100)/100)+' '+fSExt[i];
console.log('FILE SIZE = ',exactSize);
alert(exactSize);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" />
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras