validate image input file jquery Multiple 4 ways

Asked

Viewed 486 times

0

Good evening guys, I have an Multiple input file and I need to do 4 validations before sending the form.

1) Limit the number of images sent to 10

2) images have to be of type jpeg or png ( put only one Accept in html already solves this completely?)

3) each n image may be greater than 2mb

4) minimum image width should be 600px

Can you give me a strength? I was doing all this validation after sending the file to the server, but it’s bad to send it all and then test.

  • 2

    Post the code you already have so far.

  • jquery I have nothing, I searched but I didn’t find anything that fit me because all I saw were for input from a single file and I need for Multiple

1 answer

0

Hello

1) You can find your solution here

2) You can search further on google by searching how to validate file extensions. Here’s another one solution

3) Solution here

4) In Javascript format:

var largura = document.getElementById("imagem").width; // retorna a largura
    var altura = document.getElementById("imagem").height; // retorna a altura

In Jquery

var largura = $('#imagem').width(); // retorna a largura
var altura = $('#imagem').height(); // retorna a altura

Now it’s up to you, just create the required Function before sending to the server.

  • on question 4 => if the input file is Multiple will not give problem when picking up this width and height no?

  • Anyway you will need to check each file, so you would have to capture the list of files from the Multiple input and check each one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.