Is xxs_clean a callback function? Or did you mean to type xss_clean?
Also, I did use version 2.1. I’ve modified it a little bit, so that the function names were clear, removed a couple that were unnecessary, fixed some code that was a bit redundant and made some changes so that they conform more to the CodeIgniter Upload class.
I’ve posted the code, here are the links:
Thanks djenniex, neat code. By the way, it was still failing when no file specified, so I made a little modification to fix it.
Now, if no file is specified but the field is not required, no error is thrown and the validation continues.
Note: The following code it’s for djenniex’s version.
// It's a file, so process it as a file
$postdata = $_FILES[$row['field']];
// Is the file required?
$file_required = in_array('file_required', $rules);
// Before doing anything check for errors
if ($postdata['error'] !== UPLOAD_ERR_OK)
{
switch ($postdata['error'])
{
case 1: // UPLOAD_ERR_INI_SIZE
$error = $this->CI->lang->line('upload_file_exceeds_limit');
break;
case 2: // UPLOAD_ERR_FORM_SIZE
$error = $this->CI->lang->line('upload_file_exceeds_form_limit');
break;
case 3: // UPLOAD_ERR_PARTIAL
$error = $this->CI->lang->line('upload_file_partial');
break;
case 4: // UPLOAD_ERR_NO_FILE
// Set the error only if the field is required
if ($file_required) $error = $this->CI->lang->line('upload_no_file_selected');
break;
case 6: // UPLOAD_ERR_NO_TMP_DIR
$error = $this->CI->lang->line('upload_no_temp_directory');
break;
case 7: // UPLOAD_ERR_CANT_WRITE
$error = $this->CI->lang->line('upload_unable_to_write_file');
break;
case 8: // UPLOAD_ERR_EXTENSION
$error = $this->CI->lang->line('upload_stopped_by_extension');
break;
default:
if ($file_required) $error = $this->CI->lang->line('upload_no_file_selected');
break;
}
if (isset($error))
{
// Build the error message
$message = sprintf($error, $this->_translate_fieldname($row['label']));
// Save the error message
$this->_field_data[$row['field']]['error'] = $message;
if ( ! isset($this->_error_array[$row['field']]))
{
$this->_error_array[$row['field']] = $message;
}
return FALSE;
}
}
$_in_array = FALSE;
// If the field is blank, but NOT required, no further tests are necessary
$callback = FALSE;
if ( ! $file_required && $postdata['size'] == 0)
{
// Before we bail out, does the rule contain a callback?
if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
{
$callback = TRUE;
$rules = (array('1' => $match[1]));
}
else
{
return;
}
}