How can I limit the number of files that can be uploaded?
Maximum validation applies to the size of the image (in kilobytes) How do I perform a verification for the maximum number of files to upload (for example, only 10 files Can be uploaded with an input)?
In Laravel, there is no implied verification rule for it. But you can make it to handle.
There is a simple custom-verification rule for this.
customValidator.php in the app / directory.
validator :: extension ('upload_count', function ($ attribute, $ value, $ parameter) {$ files = input :: file ($ parameter [0]); return (counting ( $ Files) & lt; = $ parameter [1]) True: incorrect;}); Do not forget to add app / start / global.fp with the requirement of app_path (). '/ Customvalidator.php';
In your approval settings,
$ messages = array ('upload_count' = & gt; 'can not exceed the attribute field 3'. ,); $ Validator = validator :: make (input :: all (), array ('file' = & gt; array ('upload_count: file, 3')), // is the name of the first field and the second maximum number $ message is) ;
Hope this will be helpful for you.
No comments:
Post a Comment