Welcome Guest, Not a member yet? Register   Sign In
File Uploads - Best Practices?
#3

[eluser]Oscar Dias[/eluser]
Regarding the last question "Is it possible to make a file upload a required form field in codeigniter?". Correct me if I'm wrong, but the form_validation doesn't work with file uploads because the form_validation works only with $_POST, while file uploads use $_FILE.
I use callback functions to validate file uploads as required, as follows:
Code:
...
$this->form_validation->set_rules('picture', 'Picture', 'callback_required_file[picture]');
...

And the callback function:
Code:
public function required_file($str, $field)
{
    if (!isset($_FILES[$field]))
    {
        $this->form_validation->set_message('required_file', 'The %s field is required.');
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}


Messages In This Thread
File Uploads - Best Practices? - by El Forum - 08-15-2012, 10:17 AM
File Uploads - Best Practices? - by El Forum - 08-16-2012, 02:57 AM
File Uploads - Best Practices? - by El Forum - 08-16-2012, 05:59 AM
File Uploads - Best Practices? - by El Forum - 08-16-2012, 06:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB