0

I want to implement an HTML5 file picker <input type="file" ...> which accepts all kinds of files.

But it should let the user select image/* and video/* files. To be more precise: I'm trying to disallow images and videos. Anything else should be allowed.

The only way I currently see is to define a set of accepted file extensions (and/or mime types), but I don't think it's feasible to add a list of hundreds of mime types just to prevent that the user can select image and video files. So that wouldn't be a satisfying solution.

I'd prefer a JavaScript free solution, if possible.

tmuecksch
  • 6,222
  • 6
  • 40
  • 61
  • Your question isn't clear... are you trying to disallow video and images? Or only allow video and images? If allowing, you can set `image/*` and `video/*` on the `accept` attribute. There is no way to disallow. – Brad May 14 '20 at 16:12
  • I'm trying to disallow images and videos. Anything else should be allowed. – tmuecksch May 14 '20 at 18:21
  • This isn't possible without JavaScript. – Brad May 14 '20 at 19:19

1 Answers1

0

Hope this Below link will help you in resolving your problem basically you need to add accept attribute to your input element and add the file types as the value which you want the user to upload. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file

MD M Nauman
  • 421
  • 4
  • 10
  • Hi. The problem is, that I want the user to be able to upload all kinds of files. But not images and videos. Therefore I'd have to specify a subset of all possible extensions and/or mime types (but without video and image types). That wouldn't be a good solution imho. – tmuecksch May 14 '20 at 18:23
  • 1
    According to my knowledge, There is no direct way to disallow them but you can use javascript to check for file extension using regex pattern when there is a change event in the input and based on that alert the user otherwise allow them. – MD M Nauman May 14 '20 at 18:31