Kohana 3.2 Upload Exception -


i'm using kohana 3.2. have category form 2 upload fields: 1 image, , 1 banner. in controller got:

try{      $model_category->save();  }catch(orm_validation_exception $e){     $errors = $e->errors('forms');      //echo debug::vars($errors); }catch (exception $e){     $upload_errors = $e->getmessage(); } 

rules images in model:

'photo' => array(                      array('upload::valid'),                     array('upload::type', array(array(':value'),array('jpeg', 'jpg', 'png', 'gif'))),                     array('upload::size', array(array(':value'), array('500000')))                 ),                  'banner' => array(                         //array(array($this, 'validate_photo'), array(':validation', ':field', ':value', 500, 100)),                         array('upload::valid'),                         array('upload::type', array(array(':value'),array('jpeg', 'jpg', 'png', 'gif'))),                         array('upload::size', array(array(':value'), array('5000000')))                 ), 

i got such problem: if leave required field, example "name" , upload txt file force both exceptions occur, can catch orm_validation_exception. question how merge 2 error array. , important, how can know if it's exeception image field or banner field.

i have been trying on days end nothing. please me out!

you can use validation class validate uploads , if validation ok - save model.

something like:

    $validate_image = validation::factory($_files);      $validate_image->rule($name, 'upload::valid');     $validate_image->rule($name, 'upload::type', array($_files['image'], array('jpeg', 'jpg', 'png', 'gif')));     $validate_image->rule($name, 'upload::size', array($_files[$name], '500000'));       $validate_banner = validation::factory($_files);      $validate_banner->rule($name, 'upload::valid');     $validate_banner->rule($name, 'upload::type', array($_files[$name], array('jpeg', 'jpg', 'png', 'gif')));     $validate_banner->rule($name, 'upload::size', array($_files[$name], '500000'));      if ($validate_image->check() && $validate_banner->check()) {          $model_category->save();      } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -