Codeigniter:无法显示带有空格的上载图像并大写后续单词 [英] Codeigniter: unable to display the uploaded image with spaces and capitalizing subsequent words

查看:82
本文介绍了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.

这篇关于Codeigniter:无法显示带有空格的上载图像并大写后续单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆