Reputation: 55
While uploading csv file iam saving that file in uploads folder if the file uplaoded successfully into database or not uploaded then also it should be deleted automatically from that folder.Can any one help me regarding this.
$data['error'] = '';
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '10000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$data['error'] = $this->upload->display_errors();
}
else {
$file_data = $this->upload->data();
$file_path = './uploads/'.$file_data['file_name'];
$csv_array = $this->csvimport->get_array($file_path,'',FALSE,0,3,0,$cformat);
if ($csv_array) {
$successflag=true;
foreach ($csv_array as $row) {
$order = array(
'department'=>$row['Department'],
'gender'=>$row['Gender'],
);
$query = $this->db->query("select count(*) cnt from order_master where order_id='{$order['order_id']}' ");
$row = $query->first_row();
if(trim($order['order_id'] )!="" && $row->cnt==0 ) {
$this->masterorder_model->order($order);
}
else if ( $row->cnt>0) {
$successflag=false;
$this->flash->success("<h5><font color='red'>Found Duplicate Order Id'{$order['order_id']}' for order name '$oname'</font></h5>");
break;
}
}
if(!$successflag) {
$this->db->trans_rollback();
}
else {
$this->db->trans_commit();
$this->flash->success('<h5>Csv Data Imported Successfully.</h5>');
}
redirect(base_url().'masterorder/index');
}
else {
$this->flash->success('<h5><font color="red">Invalid file format.</font></h5>');
redirect(base_url().'masterorder/index');
}
}
}
Upvotes: 0
Views: 1763
Reputation:
you can use the file helper for the codeigniter.
So it would be like as below :
$this->load->helper("file");
delete_files($path);
Please visit this for more information.
Upvotes: 1