CodeIgniter Forums
mime_in throws error when file is not passed - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: mime_in throws error when file is not passed (/showthread.php?tid=79318)



mime_in throws error when file is not passed - sfarzoso - 05-27-2021

I have this code:

PHP Code:
  $validationRules = [
            'name'          => 'required',
            'subject'       => 'required',
            'email'         => 'required',
            'message'       => 'required',
            'sede'          => 'required',
            'attachment'    => 'mime_in[attachment,application/pdf]|max_size[3024]'
        ];

        if (!$this->validate($validationRules)) {
            return $this->fail($this->validator->getErrors());
        

which is working fine when I pass the attachment field, but since that field is optional, when I doesn't send it I get:

The file attachment does not have an allowed mime type

How can I manage this?


RE: mime_in throws error when file is not passed - paulbalandan - 05-27-2021

try to add the `permit_empty` rule