1

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Sheraz
  • 71
  • 1
  • 1
  • 7
  • A few things to check, are the files greater than your PHP max file size limit in the php.ini config? Are the files greater than 5MB as defined in your validation rules? Do the files have odd characters in their filenames? – Stieffers Aug 16 '12 at 14:35
  • the file name is "Use cases for Interviews Plugin.docx" and its size is only 101KB. – Sheraz Aug 17 '12 at 05:20
  • The $errors is showing error about file type. Array ( [applicant_cv] => type ) – Sheraz Aug 17 '12 at 07:25
  • The only thing I can suggest is trying to narrow down the issue. Is it specific to the file? Is it because the filename has spaces? Do .doc files work? – Stieffers Aug 17 '12 at 14:42

1 Answers1

0

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.

George
  • 2,860
  • 18
  • 31