上传csv文件时,如果文件已成功上传到数据库或未上传,则将该文件保存在uploads文件夹中,然后它也应该从该文件夹中自动删除。任何人都可以帮我解决这个问题。
$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');
}
}
}