I am uploading multiple images using the following code:
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
//new code
$config['upload_path'] = './uploads/advert_images';
$target_path = './uploads/advert_images/thumbs';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1000000'; //limit 1 mb
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$config['encrypt_name'] = TRUE;
$config['max_width'] = '5000';// image max width
$config['max_height'] = '5000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload('userfile');
$fileName = $_FILES['userfile']['name'];
$data = array('upload_data' => $this->upload->data());
if(!$this->upload->do_upload('userfile'))
{
$error = array('upload_error' => $this->upload->display_errors());
$this->session->set_flashdata('error', $error['upload_error']);
echo $files['userfile']['name'][$i].' '.$error['upload_error']; exit;
} // resize code
$path=$data['upload_data']['full_path'];
$file_name_new=$data['upload_data']['file_name'];
$q['name']=$_FILES['userfile']['name'];
$configi['image_library'] = 'gd2';
$configi['source_image'] = $path;
$configi['new_image'] = $target_path;
$configi['maintain_ratio'] = FALSE;
$configi['width'] = 300; // new size
$configi['height'] = 300;
$configi['file_name'] = $_FILES['userfile']['name'];
$this->load->library('image_lib');
$this->image_lib->initialize($configi);
$this->image_lib->resize();
unlink($path);
$insert[$i]['picture_file_name']=$file_name_new;
$insert[$i]['add_id']=$last_insert_id;
}
$response=$this->db->insert_batch('product_pictures',$insert);
if ($response) {
$this->session->set_flashdata('msg', 'Advert added successfully');
redirect('Site/create_adverts');
}
}
What i need to do is to delete the original files uploaded to the advert_images folder, but keep only the ones inside thumbs folder.I tried to delete using unlink, but it does not seem to work.