Maybe I am missing something simple, but I can’t seem to get my form verification just right.
How can I get the form validation to check the file verification too without doing an
$this->upload->do_upload("fldImage")
this is my verification process currently:
if ($this->form_validation->run() == FALSE)
{
if ( ! $this->upload->display_errors("fldImage"))
{
$error = array('error' => $this->upload->display_errors());
}
$this->load->view('submitBlog', $error);
}
else
{
if ( ! $this->upload->do_upload("fldImage"))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('submitBlog', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
unset($blog['submit']);
$imagePath = "uploads/".$data['upload_data']['file_name'];
$blog['fldImage'] = $imagePath;
$blog['fldDateAdded'] = $datetime;
$this->db->insert('tblBlog', $blog);
$this->load->view('submitBlogSuccess', $data);
}
}
but of course I can’t call
do_upload("fldImage")
without running
do_upload()
but if the image is valid but the other form values are not, I do not want to upload the image.
First, add the following rule:
And the following callback function:
Concept borrowed from PyroCMS. Alter where necessary.
Note: Checking for MIME-types is probably a better approach, let me know if you would like some help with that.