Set multiple mime types for upload field

Notice: This thread is very old.
gebeer
Member | 3
+
0
-

Hello,
I have an upload field which should allow pdf AND word docs.

Following the documentation, I set it up like this:

$form->addUpload('fileupload', $fields['fileupload']['label'])
    ->setRequired(FALSE) // optional
    ->addRule(Form::MIME_TYPE, $fields['fileupload']['description'], 'application/pdf' )
    ->addRule(Form::MIME_TYPE, $fields['fileupload']['description'], 'application/msword' );

But validation is only recognizing the first rule.
I also tried to pass in mime types as array in a single rule

->addRule(Form::MIME_TYPE, $fields['fileupload']['description'], ['application/pdf', 'application/msword'] );

This also doesn't work.

How can I define 2 valid mime types for an upload field?

Any hints would be much appreciated. Thank you.

CZechBoY
Member | 3608
+
0
-

Array should work.
Are you sure that mime type has really that value? Try to dump it.

gebeer
Member | 3
+
0
-

Thank you for the quick answer.

This is the dump of the uploaded file:

fileupload => array (5)
name => "Betz_Aßmus.doc" (15)
type => "application/msword" (18)
tmp_name => "/tmp/phpCAjHfg" (14)
error => 0
size => 2898

And here is my upload field definition with mime types as array:

$form->addUpload('fileupload', $fields['fileupload']['label'])
    ->setRequired(FALSE) // optional
    ->addRule(Form::MIME_TYPE, $fields['fileupload']['description'], ['application/pdf', 'application/msword'] )
    ->addRule(Form::MAX_FILE_SIZE, __("Maximale Dateigröße von 5 MB überschritten."), 5*1024*1024);

So the mime type of the file is correct but still, it does not pass validation.
Even if I pass only application/msword as string to the mime type rule, it does not pass.