Welcome Guest, Not a member yet? Register   Sign In
Upload PDF file (not required)

I have problem with form validation for upload file, here my validation rule

'file' => [
              // 'uploaded[file]',

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');

if ( !empty(
$uploaded_file) ) 
    // File was uploaded, run other validation here
    // No file was uploaded


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 )

Theme © iAndrew 2016 - Forum software by © MyBB