繁体   English   中英

上传时避免在文件名中用下划线替换空格

[英]Avoid replacing of space in filename with underscore while uploading

我在Codeigniter中有一个要上传文件的表单。 如果文件名包含空格,例如: images(1).jpg ,则该文件将作为images_(1).jpg上载到安全文件夹中。 如何避免这种情况? 我想用图像的相同名称上传它,例如: images(1).jpg

我在访问文件名时使用了trim()

$thumbfile=trim($_FILES['thumb_image']['name']);

对于文件上传,我使用了以下代码部分:

$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);

谁能帮我解决这个问题。 提前致谢。

尝试$config['remove_spaces'] = FALSE;

否则,请在核心上传库中查找$this->file_name = preg_replace("/\\s+/", "_", $this->file_name); do_upload方法中可以更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM