Jen*_*enz 1 php codeigniter file-upload
我在 Codeigniter 中有一个表单,我正在上传一个文件。如果文件名包含空格,例如:images (1).jpg那么,它将作为images_(1).jpg上传到安全文件夹中。如何避免这种情况?我想使用与图像相同的名称上传它,例如:images (1).jpg。
我trim()在访问文件名时使用过:
$thumbfile=trim($_FILES['thumb_image']['name']);
Run Code Online (Sandbox Code Playgroud)
对于文件上传,我使用了以下代码段:
$config1['upload_path'] = './secure/'.$lastid;
$ext = end(explode(".", $_FILES['thumb_image']['name']));
$config1['file_name'] = trim($_FILES['thumb_image']['name']);
$config1['allowed_types'] = 'jpg|png|jpeg|gif|bmp|jpe|tiff|tif';
$this->load->library('upload', $config1);
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个问题。提前致谢。
尝试 $config['remove_spaces'] = FALSE;
否则,请查看核心上传库,您将$this->file_name = preg_replace("/\s+/", "_", $this->file_name);在do_upload其中看到可以更改的方法。