下面是我在codeigniter中的上传功能。我可以上传文件。我还检查文件名是否与 url 参数匹配。如果名称与 url 不匹配,我如何删除文件。我尝试了取消链接功能,但它不起作用
function do_upload() {
$this->makeDir();
$labref = $this->uri->segment(3);
$filename = 'xyz/'. date('Y').'/'.date('M').'/'. $labref .'/' . $labref . '.xlsx';
if (file_exists($filename)) {
$data['labref'] = $this->uri->segment(3);
$data['settings_view'] = 'analyst_file_present_v';
$this->base_params($data);
} else {
$config['upload_path'] = 'xyz/'. date('Y').'/'.date('M').'/'. $labref ;
$config['allowed_types'] = 'xls|xlsx';
$this->load->library('upload', $config);
$data= $this->upload->data();
if ($data['file_name']=="$labref.'.xlsx'") {
$this->SaveFileDetails();
$this->success();
}else{
$filename = 'xyz/'.date('Y').'/'.date('M').'/'. $labref.'/'.$labref.'xlsx' ;
unlink($filename);
echo 'You have uploaded a wrong file';
}
if (!$this->upload->do_upload('worksheet')) {
$data['labref'] = $this->uri->segment(3);
$data['error'] = $this->upload->display_errors();
$data['settings_view'] = 'upload_analyst_v';
$this->base_params($data);
}
}
}