2

I was trying to find a html way to define maximum amount of files that can be selected by the input like this:

<div class="form-field">
    <label for="images[]">{{t('label.images')}}</label>
    <input type="file" name="images[]" multiple>
    <p class="right-infobox">{{t('label.images-info')}}</p>
</div>

As you can see I'm using Laravel, but this does not matter in this case. The problem is, user can select as many images as he wants.

I would like to define it on the client side somehow without JavaScript. If I don't prevent it, this will eat my traffic with no reason and I will get rid of rest images anyway.

ForceBru
  • 43,482
  • 10
  • 63
  • 98
rkd.me
  • 140
  • 8
  • possible duplicate of [How to limit maximum items on a multiple input ()](http://stackoverflow.com/questions/10105411/how-to-limit-maximum-items-on-a-multiple-input-input-type-file-multiple) – Mark Sep 19 '15 at 12:50
  • You can not define file size in html form you can check it using javascript if you want – Domain Sep 19 '15 at 12:50
  • 1
    well, so there is no way in pure html? I know i can use jQuery or JS, but that was not the question. – rkd.me Sep 19 '15 at 12:54
  • 1
    If you truly want to limit the user to `n` files, you could just provide a UI with `n` file inputs. It's not ideal in terms of user experience but may be the only HTML-only way. However, I would recommend just using JavaScript. – Drew Gaynor Sep 19 '15 at 13:11
  • Yeah, I just wanted to provide one input field for the users instead of 5, it just looks better and it's more user-friendly. Sad there is no way in pure HTML, I will workaround it with JavaScript, because it must be blocked. Thanks – rkd.me Sep 19 '15 at 13:24
  • Blocking with javascript is not very useful if it really "*must be blocked*". You must guard your server as well. – Amit Sep 19 '15 at 16:00
  • Yeah Im aware of that... But this will save at least some traffic – rkd.me Sep 19 '15 at 19:09

0 Answers0