Hello everyone
I am using uplaod library and form validation library.
Code:
PHP Code:
$this->form_validation->set_rules('title', 'title', 'trim|required|min_length[5]|max_length[50]|htmlspecialchars');
$this->form_validation->set_rules('upload', 'file', 'callback_handle_upload');
handle_upload:
PHP Code:
function handle_upload(){
if (isset($_FILES['upload']) && !empty($_FILES['upload']['name'])){
if ($this->upload->do_upload('upload')){
// set a $_POST value for 'image' that we can use later
$upload_data = $this->upload->data();
$_POST['upload'] = $upload_data['file_name'];
return true;
}else{
// possibly do some clean up ... then throw an error
$this->form_validation->set_message('handle_upload', $this->upload->display_errors());
return false;
}
}else{
// throw an error because nothing was uploaded
$this->form_validation->set_message('handle_upload', "cannot be empty");
return false;
}
When i submit my form, and for example the title is wrong so the file is uploading to my server.
I know why this is happen, because:
PHP Code:
$this->upload->do_upload('upload')
is inside handle_upload();
I did not know how to solve this problem.
I want to show errors with Form_validation (including upload errors) and upload the file only if all the other fields are correct.
Help please?
Thank you