I am trying to validate file upload for image uploading, but it is not getting the validation like other fields. I am using Form_Validation.php
process for validation.
Image uploading array:
array(
'field'=>'image',
'label' => 'Image',
'rules' => 'required'
)
when i try to upload the image it did not response like it is required etc. I also want to validate it for .jpg
etc and "how to set the file value on incorrect file like instead of .jpg
we try to upload the .pdf
" like we set the value of input field set_value('field name')
etc.
I checked a lot of questions and also try to use call method, but did not able to fix it.
UPDATE:
Please provide detail answer with code example. Please use the form_validation.php way in example and also provide the callback example code, so i can read / learn and modify it accordingly.
UPDATE 2:
public function Task()
{
if ($this->form_validation->run('Sub_Admin/task') == FALSE) {
$this->data['Task'] = $this->bm->get_usr();
$data['title'] = "Add New Task";
$this->load->view('Subadmin/header',$data);
$this->load->view('Subadmin/nav');
$this->load->view('Subadmin/sidebar');
$this->load->view('Subadmin/task', $this->data);
$this->load->view('Subadmin/footer');
}
else
{
$config['upload_path'] = './taskimages/'; //The path where the image will be save
$config['allowed_types'] = 'gif|jpg|png'; //Images extensions accepted
$config['max_size'] ='10048'; //The max size of the image in kb's
//$config['max_width'] = '1024'; //The max of the images width in px
//$config['max_height'] = '768'; //The max of the images height in px
$config['overwrite'] = FALSE; //If exists an image with the same name it will overwrite. Set to false if don't want to overwrite
$this->load->library('upload', $config); //Load the upload CI library
$this->load->initialize($config);
$this->upload->do_upload('task');
$file_info = $this->upload->data();
$file_name = $file_info['file_name'];
$data = array(
'Job_Title' => $this->input->post('jtitle'),
'Priority' => $this->input->post('jnature'),
'Assignee' => $this->input->post('assigne'),
'Employee_Name' => $this->input->post('assignto'),
'Due_Date' => $this->input->post('ddate'),
'Reminder' => $this->input->post('reminder'),
'Task_Image' => $file_name,
);
$this->bm->add_task($data);
}
}
I am already using CI uploading class but it is not working, and now i want to validate the image/ file from form_validation side.
I am using this code for multiple images upload. Now try below code, Hope it will help.
Currently you are not getting error because you set validation rules, you also initialized configuration but after uploading class you are not checking that either file is being uploaded or errors.
Please check below mentioned solution, it will help you fix this.
Update 1 :
In order to call a specific group, you will pass its name to the
$this->form_validation->run('task')
method. I can not see any$config['task']
array in your code. Please check my below mentioned code and update based on yourinputs
.Let me know if it not works.
Here I write only sample files upload. Change it according to your requirement. controller/Files.php
view/upload_view.php
Try this
How about File Uploading Class from CI?
Validations are also available from the class:
The link includes the Upload form, Success page and the Controller.
Just follow the instructions from there and you'll never get lost.
You are not getting error using CI uploading class because you are not calling error meothod of it. Change your update 2 code as below
In view