i am uploading four images from my form but the images are not uploading. I pasted my code below. Please correct me where i done mistake. first i did validation and then i configured the and path. Later i loaded upload library and later given image path for each image.
my Controller Code
public function upro()
{
$this->form_validation->set_rules('pro_name','Product','required');
$this->form_validation->set_rules('pro_image1','Image1','required');
$this->form_validation->set_rules('pro_image2','Image2','required');
$this->form_validation->set_rules('pro_image3','Image3','required');
$this->form_validation->set_rules('pro_image4','Image4','required');
// $today = date('Y-m-d');
if($this->form_validation->run()){
function uploadPic()
{
$config=[
'upload_path' => './uploads',
'allowed_types' => 'jpg|gif|png|jpeg'
];
$this->load->library('upload',$config);
}
$data = $this->input->post();
$today = date('Y-m-d');
$data['pro_date'] = $today;
$info = $this->upload->data();
$image_path = base_url("uploads/".$info['raw_name'].$info['file_ext']);
$data['pro_image1'] = $image_path;
$data['pro_image2'] = $image_path;
$data['pro_image3'] = $image_path;
$data['pro_image4'] = $image_path;
unset($data['submit']);
$this->adata->uproQ($data);
$this->session->set_flashdata('msg','Product uplaod success');
return redirect('admin/products');
}else{
$this->session->set_flashdata('msg','product uplaod failed');
return redirect('admin/apro');
}
}
my model Code
public function uproQ($data)
{
return $this->db->insert('products',$data);
}
my form view Code
<?php echo form_open_multipart('admin/upro');?>
<label><h5>product Name:*</h5></label>
<?php echo form_input(['name'=>'pro_name','class'=>'form-control','placeholder'=>'product Name Here','value'=>set_value('pro_name')]);?>
<?php echo form_upload(['name'=>'pro_image1']);?>
<label><h5>product Image2:*</h5></label>
<?php echo form_upload(['name'=>'pro_image2']);?>
<label><h5>product Image3:*</h5></label>
<?php echo form_upload(['name'=>'pro_image3']);?>
<label><h5>product Image4:*</h5></label>
<?php echo form_upload(['name'=>'pro_image4']);?>
<button type="reset" class="btn btn-warning">Reset</button> <button type="submit" class="btn btn-primary">Submit</button><hr>
<?php form_close();?>