如果文件包含字符,我想上传文件并删除字符,但是如果我尝试使用preg_replace删除文件,则该文件将不起作用并保留原始名称
有人可以帮我吗?
function add_attachment()
{
$config['upload_path'] = './myfile/';
$config['allowed_types'] = 'pdf|xlsx|xls|csv|doc|docx';
$config['no_space'] = TRUE;
$config['file_name'] = preg_replace('/[^a-zA-Z0-9.]/','',basename($_FILES['files']['name']));
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('file_upload'))
{
print_r($this->upload->display_errors());
}
else
{
$filename = $this->upload->data();
$file = $filename['file_name'];
$id = $this->uri->segment(3);
$idc = $this->uri->segment(4);
$data = array(
'id_request' => $id,
'file_name' => $file,
'status_confidential' =>$this->input->post('status_confidential')
);
$this->request_model->add_request_file($data);
redirect('request/view_request/'.$id.'/'.$idc);
$this->db->close();
}
}