Upload PDF file (not required) |
I have problem with form validation for upload file, here my validation rule
'file' => [ // 'uploaded[file]', 'mime_in[file,application/pdf,image/jpg,image/jpeg,image/gif,image/png]', 'max_size[file,4096]', ], However, if I don't upload the image, it shows validation error. How to set this validation rule only to apply to an uploaded file?
First, you need to check if the file was submitted before you do any validation.
You can do so by using the [code]getFiles()[\code] function provided by CI. See documentation: Working with Uploaded Files — CodeIgniter 4.0.4 documentation So your code would look like this: PHP Code: $uploaded_file = $this->request->getFiles('file');
You can read about it here in the CodeIgniter 4 - Users Guide.
CodeIgniter 4 User Guide - Working with Uploaded Files What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |