I am new user to using code igniter in my project, I am facing one problem while uploading multiple files but the last one only insert to all image three images field.
my controller is:
function products()
{
date_default_timezone_set("Asia/Kolkata");
$config['upload_path'] = './resources/images/products/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data = array('prod_image' => $this->upload->data(),
'prod_image1' => $this->upload->data(),
'prod_image2' => $this->upload->data());
$product_image=$data['prod_image']['file_name'];
$product_image1=$data['prod_image1']['file_name'];
$product_image2=$data['prod_image2']['file_name'];
$data = array(
'name' => $this->input->post('pd_name'),
'prod_image' => $product_image,
'prod_image1' => $product_image1,
'prod_image2' => $product_image2,
'created_time' => date('Y-m-d H:i:s'));
// insert form data into database
$result_set= $this->tbl_products_model->insertUser($data);
}
my view part is:
<input class="form-control" name="pd_name"type="text"/>
<input type="file" class="file_upload2" name="userfile"/> //1
<input type="file" class="file_upload2" name="userfile"/> //2
<input type="file" class="file_upload2" name="userfile"/>//3
Please help how to insert 3 images.
my datad base like
===========================================
id|name|prod_image|prod_image1|prod_image2|
===========================================
1|ard| | | |
============================================
Multiple files uploads unlimited files
Database table(profile_images) column names are image_name(255,varcher), added_datetime(current timestamp)
View
Controller
Model
Html :
PHP :
The problem is with the following line of code:
These all three have same name.
To solve this there are two ways:
Give diff name to all 3 input type file
Make a single input type file with its multiple file selection true and its name must be an array like:
Make the following changes and try again.