简体   繁体   English

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

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

I have a form in Codeigniter in which I am uploading a file. 我在Codeigniter中有一个要上传文件的表单。 If the file name contains space eg: images (1).jpg then, it is getting uploaded in the secure folder as images_(1).jpg . 如果文件名包含空格,例如: images(1).jpg ,则该文件将作为images_(1).jpg上载到安全文件夹中。 How to avoid this? 如何避免这种情况? I want to upload it with the same name of the image eg: images (1).jpg . 我想用图像的相同名称上传它,例如: images(1).jpg

I have used trim() while accessing the file name as: 我在访问文件名时使用了trim()

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

For file uploading, I have used the following section of code : 对于文件上传,我使用了以下代码部分:

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

Can anyone help me to solve this problem. 谁能帮我解决这个问题。 Thanks in advance. 提前致谢。

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

Otherwise, look in the core upload library where you'll see the $this->file_name = preg_replace("/\\s+/", "_", $this->file_name); 否则,请在核心上传库中查找$this->file_name = preg_replace("/\\s+/", "_", $this->file_name); in the do_upload method which you can alter. do_upload方法中可以更改。

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

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