#1
I have this statement
$this->validation_helper->set_rules('myfile', 'file', 'required|validate_file|allowed_types[txt,csv,pdf]|max_size[20000]');
$result = $this->validation_helper->run();

I tried removing validate_file, but still get the die statement.
It looks like the required is not getting executed in the validation helper because the file_validation_helper is executed first.

die('ERROR: Invalid validation rule.');

It works if I remove the die statement in the file_validation_helper and make the following changes in the validation_helper.
// $posted_value = $_FILES[$key];
//$tests_to_run[] = 'validate_file';
$posted_value = $_FILES[$key]['name'];
$tests_to_run = $this->get_tests_to_run($rules);
#2
Hi frocco,

I don't understand the logic in your rules you are trying to check > 'required' & 'validate_file'.

On line 9 of the validation_helper:

As the super global '$_FILES' is set, the default is to check 'validate_file' first, by setting

So there is no need to check for 'validate_file' in your rules, and 'required' will always be true, because $_FILES[$key]['name'] is set.

Here is the full method (with your 2 lines commented out):


so even if you force the rules to:

by uncommenting the two lines above and commenting the 2 original lines. The run_validation_test() method will check 'required' first from the $test_to_run() array and the 'check_for_required' method will always be true as the file name from $posted_value will never equal "".

Also, commenting out line 109 of the file_validation_helper.php
is just short circuiting '$file_check_key' as 'validate_file' is not being checked, only ['allowed_types', 'max_size', 'max_height', 'max_width', 'min_height', 'min_width', 'square'] are being checked.

So your solution is to restore the validation_helper.php & file_validation_helper.php to their original states and remove 'required|validate_file' from your rules as they are being checked by default, and adding them to the rules is only going to break your code.

Try this:


Cheers,
Si
#3
Thank you DaFa for taking the time to correct my logic.
#4
You're welcome Frocco,

If you could please close off this thread and the others left open, that would be appreciated.