Codeigniter:无法显示带有空格的上载图像并大写后续单词

问题描述:

从下面的代码中,我可以上传带有空格的图像并大写后续的单词,但是如果我尝试将此类图像查看到我的视图页面中,则该图像不可见.我收到类似The URI you submitted has disallowed characters.

From my below code i am able to upload images with spaces and capitalizing subsequent words, but if i try to view such images into my view page then its not visible. I am getting error like The URI you submitted has disallowed characters.

我正在显示类似<img src="<?php echo base_url().'uploads/avatar/'.$avatar?>"/>的图像 因此,我该如何解决此错误,以允许img标签读取带有空格的图像名称并大写后续的单词.

I am displaying images like <img src="<?php echo base_url().'uploads/avatar/'.$avatar?>"/> So how can i fix this error, to allow img tag to read image name with spaces and capitalizing subsequent words.

或其他解决方案,如何在上传时删除空格或将后续单词用图片名称大写?

Or alternative solution, How how can i remove any spaces or capitalizing subsequent words with the image name while uploading?

我正在使用以下代码上传文件.

I am uploading file with the below code.

   function do_upload()
        { 
         $this->load->library('form_validation'); 

        if((isset($_FILES['userfile']['size'])) && ($_FILES['userfile']['size'] > 0))
            {
                 $this->form_validation->set_error_delimiters('<li  class="errorlist">', '</li>')->set_rules('userfile', 'New Image', 'trim|callback_valid_upload_userfile');   
            }    
      $uid=$this->session->userdata('userid');
    $config['upload_path'] = './uploads/avatar/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '5000'; 
    $this->load->library('upload', $config);  

 if ( $this->input->post('user_id') && $this->form_validation->run() == TRUE)
 {  
         $avatar= $_FILES['userfile']['name'];  //getting the file name  
          $this->loginmodel->update_user_basic_info($uid); //update both 

    }

这很简单,请使用:

$config['remove_spaces'] = TRUE;

因此,在上传过程之后,您必须从$this->upload->data()中获取文件名,而从$_FILES中获取不是.

So you have to take the filename from $this->upload->data() and not from $_FILES after the upload process.