1
I have a input file in which I limited to only accept file whose format is a text file, with extension .txt
.
I used the attribute accept
for this, see:
accept=".txt"
However, I would like to know if it is possible to check using jQuery, the file format and type in the case of attribute accept
fail?
Mcve
Illustration:
function verificarArquivoTexto(arq)
{
}
$(
function ()
{
$('input:file').change(
function(e)
{
var arq = $(this).val().split('\\').pop();
$('.arquivo').html(arq);
}
);
}
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input id="upload" type="file" name="file-upload" accept=".txt">
<div class="arquivo">
</div>
I would set aside to check front-end mimetype and focus more on file extension and weight. Even if you were trying to send a file. txt other than . txt, you can do this on the server. The front end has more function to avoid unnecessary requests to the server, but can be changed and a very low % of clients will waste time with it.
– Sam