CodeIgniter Forums
want to read the contents of files and need validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Choosing CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=8)
+--- Thread: want to read the contents of files and need validation (/showthread.php?tid=87035)



want to read the contents of files and need validation - JohanBellri - 03-09-2023

In my CodeIgniter project, I want to read the contents of files and need validation to confirm if a file is selected. I have written code in the controller using $this->form_validation->set_rules() function, but I am getting an error that says "The Project Estimation File field is required" even after selecting a file. What could be the issue?


RE: want to read the contents of files and need validation - digitalarts - 03-09-2023

See: https://codeigniter.com/user_guide/libraries/validation.html?highlight=validation#rules-for-file-uploads


RE: want to read the contents of files and need validation - JohnrxBreme - 04-10-2023

you are trying to validate a file upload field in your CodeIgniter project using the form validation library, but encountering an error message that the file field is required even after selecting a file.

There are several possible reasons why this error message is being displayed. Here are a few things you can check:

Make sure that the name attribute of your file input field matches the name specified in your validation rule. For example, if you have set a validation rule for a file input field named "project_estimation_file", then the name attribute in your HTML should also be "project_estimation_file".

Verify that the enctype attribute in your form tag is set to "multipart/form-data". This is necessary for file uploads to work properly.

Check if there are any file upload restrictions set in your php.ini file. For example, if the maximum file size is set to a lower value than the size of the file you are trying to upload, this could cause the validation to fail.

Verify that the file input field is actually being submitted as part of the form data. You can check this by inspecting the network tab in your browser's developer tools to see if the file is being sent as part of the form data.

If none of the above suggestions work, you could try debugging your code by printing out the values of the $_FILES array and checking if the file input field is being populated with the uploaded file.

I hope this helps you to identify the issue and resolve the error message you are encountering. Let me know if you have any further questions or concerns.


RE: want to read the contents of files and need validation - InsiteFX - 04-11-2023

Show your code for the form and validation.