上传文件中的php空间自动替换为下划线

时间:2017-01-25 09:01:08

标签: php linux codeigniter

我使用php脚本上传文件,然后通过url显示它。如果上传文件包含空格,则无需任何理由将其替换为下划线。这个名字的改变对我来说是不受欢迎的,如何阻止它?我使用ubuntu操作系统与PHP作为编程语言和codeigniter作为框架。我正在进行multiupload,即用户可以一次上传多个文件。 注意:文件名的数据库条目不会用下划线替换空格。

    for($i = 0; $i < $filesCount; $i++){
        $_FILES['userFile']['name'] = $_FILES['docs']['name'][$i];
        $_FILES['userFile']['type'] = $_FILES['docs']['type'][$i];
        $_FILES['userFile']['tmp_name'] = $_FILES['docs']['tmp_name'][$i];
        $_FILES['userFile']['error'] = $_FILES['docs']['error'][$i];
        $_FILES['userFile']['size'] = $_FILES['docs']['size'][$i];

        $config['upload_path'] = './companies/'.$this->company_name.'/';
        $config['allowed_types'] = 'gif|jpg|png|pdf|text|zip|doc|docx'; //Allowed file types
        $this->load->library('upload', $config);
        $this->upload->initialize($config);

        if($this->upload->do_upload('userFile')){
          $data['save_name']=$_FILES['userFile']['name'];
          if(!$this->clientdb->store($data))   // this calls storing function
             die('Error : Database connection aborted abruptly.');
        }
      }     // for loop

1 个答案:

答案 0 :(得分:1)

由于配置更改CI提供的默认机制 使用以下代码

以上$this->load->library('upload', $config);

    $config['remove_spaces'] = FALSE;