【问题标题】:Avoid replacing of space in filename with underscore while uploading上传时避免用下划线替换文件名中的空格
【发布时间】:2014-04-28 12:28:23
【问题描述】:

我在 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);

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

【问题讨论】:

  • 这是 Codeigniter 上传库的默认功能。由于这个事实,你将不得不破解 codeigniter 核心。
  • 试试 $thumbfile = str_replace(' ', ' ', $_FILES['thumb_image']['name']);
  • @MohitJain 没用。

标签: php codeigniter file-upload


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 2014-11-30
    • 2014-11-27
    • 2013-01-01
    • 2016-09-05
    • 2018-01-28
    • 1970-01-01
    相关资源
    最近更新 更多