how to validate doc file in kohana 2.x

669 views Asked by At

I am trying to validate files uploaded by users. I am using Kohana 2.3.4.

I have applied validation rule for files. Only the doc, docx and PDF are allowed to be uploaded. But the problem is that it is validating the pdf but not the doc or docx.

Here is my code

$file = Validation::factory($_FILES);       
$file->add_rules('applicant_cv','upload::valid','upload::required','upload::type[doc,docx,pdf]','upload::size[5M]');

if($file->validate()){
    echo 'No validation errors found ';
}
else{

    echo 'Validation errors were found for uploader'.'<br />';
    $errors = $file->errors();
    foreach ($errors as $key => $val)
    {
        echo $key.' failed rule '.$val.'<br />';
    }

}

Please guide me how to resolve this problem.

1

There are 1 answers

0
George On

Have you checked your mimes config (default is in system/config/mimes.php) to see if you have the mime types specified for the extensions that aren't working? This is the third check that upload::type does.