Imri Persiado
Imri Persiado

Reputation: 47

Upload specific files only

I would like to limit the user to upload only specific files.I know it can be done through php script which the form action value is leading to but that's not what I'm looking for.

When the user is choosing a file after using that line:

<input type="file" ... />

He got an option to select all files

enter image description here

I want to change it only to a specific extensions.

Upvotes: 2

Views: 901

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039160

You could use the accept attribute. For example if you wanted to limit to all image files:

<input type="file" accept="image/*" />

You could also specify a list of possible types:

<input type="file" accept="image/*,video/*" />

Needless to say that legacy browsers that do not support this new attribute will behave exactly as shown in your screenshot and completely ignore this attribute and there's nothing you could do about it.

In all cases you should provide a server side validation of the actual file type being uploaded and never rely on the client to ensure this.

Upvotes: 3

Related Questions