WeAreRight
WeAreRight

Reputation: 905

php space in uploaded file replaced by underscore automatically

I am uploading files using php script and later displaying it through url. If uploading file contains space it get replaced with the underscore without any reason. This change of name is unwanted to me , how to stop it? I am using ubuntu operating system with PHP as programming language and codeigniter as a framework. I am doing multiupload i.e user can upload more than one file at a time. Note : Database entry for filename doesn't replace space with underscore.

    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

Upvotes: 1

Views: 429

Answers (1)

Nishant Nair
Nishant Nair

Reputation: 2007

It due to config change default mechanism provided by CI Use below code

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

    $config['remove_spaces'] = FALSE; 

Upvotes: 2

Related Questions