laravel - Limit number of files that can be uploaded -


how can limit number of files can uploaded?

the max validation seems apply size of image (in kilobytes). how can make validation maximum number of files allowed uploaded (for example, 10 files can uploaded single input)?

in laravel, there no built-in validation rule that. can create custom-validation rule handle this.

here simple custom-validation rule it.

create customvalidator.php in app/ directory.

validator::extend('upload_count', function($attribute, $value, $parameters) {        $files = input::file($parameters[0]);      return (count($files) <= $parameters[1]) ? true : false; }); 

don't forget add app/start/global.php

require app_path().'/customvalidator.php'; 

in validation setting,

$messages = array(     'upload_count' => 'the :attribute field cannot more 3.', );  $validator = validator::make(     input::all(),     array('file' => array('upload_count:file,3')), // first param field name , second max count     $messages );  if ($validator->fails()) {      // show validation error } 

hope useful you.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -