public function save_multiple_images()
{
for($i=0; $i<$total_items; $i++)
{
if(!empty($_POST['item_name'][$i]) && !empty($_POST['item_name'][$i]))
{
if(isset($_FILES['item_image']['name'][$i]))
{
$this->load->library('upload');
$files = $_FILES;
$_FILES['userfile']['name'] = $files['item_image']['name'][$i];
$_FILES['userfile']['type']= $files['item_image']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['item_image']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['item_image']['error'][$i];
$_FILES['userfile']['size']= $files['item_image']['size'][$i];
$fileName = $_FILES['userfile']['name'];
//Calls set upload funtions
$this->upload->initialize($this->set_upload_options($i));
if($fileName!='')
{
$this->upload->do_upload();
$upload_data = $this->upload->data();
$fileSize = $upload_data['file_size'];
if($this->upload->display_errors())
{
echo json_encode($this->upload->display_errors()); exit;
}
$fileName = base_url('files/reward_images/'.$upload_data['file_name']);
}
else{
$fileName = base_url('files/reward_images/no_image.png');
}
}
$reward_image = $fileName;
$item_id =0;
$res = $this->rewards_model->save_reward_item($reward_image);
}
}
}
}
private function set_upload_options($i)
{
//upload an image options
$config = array();
$config['upload_path'] = './files/reward_images/';
$config['file_name'] = 'File'.time().$i;
$config['allowed_types'] = '*'; \
$config['max_size'] = '52528800';
$config['overwrite'] = FALSE;
return $config;
}
{
for($i=0; $i<$total_items; $i++)
{
if(!empty($_POST['item_name'][$i]) && !empty($_POST['item_name'][$i]))
{
if(isset($_FILES['item_image']['name'][$i]))
{
$this->load->library('upload');
$files = $_FILES;
$_FILES['userfile']['name'] = $files['item_image']['name'][$i];
$_FILES['userfile']['type']= $files['item_image']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['item_image']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['item_image']['error'][$i];
$_FILES['userfile']['size']= $files['item_image']['size'][$i];
$fileName = $_FILES['userfile']['name'];
//Calls set upload funtions
$this->upload->initialize($this->set_upload_options($i));
if($fileName!='')
{
$this->upload->do_upload();
$upload_data = $this->upload->data();
$fileSize = $upload_data['file_size'];
if($this->upload->display_errors())
{
echo json_encode($this->upload->display_errors()); exit;
}
$fileName = base_url('files/reward_images/'.$upload_data['file_name']);
}
else{
$fileName = base_url('files/reward_images/no_image.png');
}
}
$reward_image = $fileName;
$item_id =0;
$res = $this->rewards_model->save_reward_item($reward_image);
}
}
}
}
private function set_upload_options($i)
{
//upload an image options
$config = array();
$config['upload_path'] = './files/reward_images/';
$config['file_name'] = 'File'.time().$i;
$config['allowed_types'] = '*'; \
$config['max_size'] = '52528800';
$config['overwrite'] = FALSE;
return $config;
}
Welcome
ReplyDelete