Reputation: 527
I need some assistance with how to save path for multiple images saved in 'upload' folder in a table. I am totally lost here.
I have this app which uploads multiple pictures perfect, but they are not linked with db anywhere.
This is controller which is actually a callback_ function:
private $_uploaded;
public function fileupload_check() {
$number_of_files = sizeof($_FILES['uploadedimages']['tmp_name']);
$files = $_FILES['uploadedimages'];
for($i=0;$i<$number_of_files;$i++) {
if($_FILES['uploadedimages']['error'][$i] != 0) {
$this->form_validation->set_message('fileupload_check', 'At least 1 image needed.');
return FALSE;
}
}
$this->load->library('upload');
$config['upload_path'] = FCPATH . 'uploads/';
$config['allowed_types'] = 'gif|jpg|png';
for ($i = 0; $i < $number_of_files; $i++) {
$_FILES['uploadedimage']['name'] = $files['name'][$i];
$_FILES['uploadedimage']['type'] = $files['type'][$i];
$_FILES['uploadedimage']['tmp_name'] = $files['tmp_name'][$i];
$_FILES['uploadedimage']['error'] = $files['error'][$i];
$_FILES['uploadedimage']['size'] = $files['size'][$i];
$this->upload->initialize($config);
if ($this->upload->do_upload('uploadedimage')) {
$this->_uploaded[$i] = $this->upload->data();
} else {
$this->form_validation->set_message('fileupload_check', $this->upload->display_errors());
return FALSE;
}
}
return TRUE;
}
How do I save the path for each image in db if I have a field in tabel 'images_path'?
Thanks in advance.
Upvotes: 0
Views: 319
Reputation: 123
In if condition Try this code.
$data['upload_data'] = $this->upload->data();
$image_name = $data['upload_data']['file_name'];
and if you print $data like this:
echo "<pre>"; print_r($data);
you will get whole array which includes path , name , image tyepe etc.
Upvotes: 1