当我在文件夹中上传文件时,空白被删除。但是,当将数据插入MySQL数据库时,不会删除空白。
控制器
public function create(){
// Check login
if(!$this->session->userdata('logged_in')){
redirect('users/login');
}
// Upload Image
$config['upload_path'] = './assets/images/posts';
$config['allowed_types'] = 'gif|jpg|png|chm|doc|dcom|docx|dot|dotx|hwp|odt|pdf|pub|rtf|xps|key|odp|pps|ppsx|ppt|pptm|pptx|PDF|DOC|XML|DOCX';
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$config['remove_spaces'] = TRUE;
$config['file_name'] = time().$_FILES['userfile']['name'];
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image = 'noimage.jpg';
} else {
$remove = $config['remove_spaces'] = TRUE;
$data = array('upload_data' => $this->upload->data());
$post_image = $remove.time().$_FILES['userfile']['name'];
}
$this->Document_model->create_document($post_image);
// Set message
$this->session->set_flashdata('category_created', 'Your Department has been created');
redirect('patient');
}
答案 0 :(得分:0)
据我了解,您想在保存数据库的同时从file_name字段中修剪空间。
请在控制器功能中进行以下更改:
$current_time = time();
$filename = trim($current_time.$_FILES['userfile']['name']);
$config['file_name'] = $filename; // replace this line with $config['file_name'] = time().$_FILES['userfile']['name'];
$post_image = $filename; // replace this line with $remove.time().$_FILES['userfile']['name'];