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



我正在使用php脚本上传文件,然后通过url显示它。如果上传文件包含空格,则会无缘无故地将其替换为下划线。这个改名对我来说是不需要的,如何阻止它?我正在使用 ubuntu 操作系统,PHP 作为编程语言,代码点火器作为框架。我正在进行多重上传,即用户可以一次上传多个文件。注意:文件名的数据库条目不会用下划线替换空格。

    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

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

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

    $config['remove_spaces'] = FALSE; 

最新更新