How do you get the HTML Browse button to filter and display only images?

On an HTML page using the INPUT tag, how can you get it so that when you click the browse button it filters only for image files? Bonus points if they can contain .bmp files.

+3
source share
6 answers

With the accept attribute, you specify the mime types to accept.

<form action="form_action.asp" accept="image/gif, image/jpeg">
    First name: <input type="text" name="fname" /><br />
    Last name: <input type="text" name="lname" /><br />
    Your image: <input type="file" name="pic" id="pic" /><br />
    <input type="submit" value="Submit" />
</form>

Taken from here .

+1
source

In theory, with an attribute.

In practice, you cannot.

I believe that most people who want to do this are related to Flash.

+1
source

accept HTML <form> , -. Flash Java-. . . Uploadify, SWFUpload JumpLoader. Uploadify .

+1

"accept" .

:.

<input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />

EDIT: , . , JavaScript.

0

What you say is to accept an attribute that, unfortunately, is not supported by any browser.

0
source

Presumably you should use the accept attribute with the correct MIME type as follows:

<input type="file" name="pic" id="pic" accept="image/bmp" />

Unfortunately, these browsers are not currently supported. However, you can check the file using javascript. Here is a useful link with the code: http://www.cs.tut.fi/~jkorpela/forms/file.html#filter

Hope this helps!

0
source

Source: https://habr.com/ru/post/1746092/


All Articles