dqd54099 2018-03-17 04:38
浏览 94
已采纳

Codeigniter:上传路径似乎无效

I am using the following function in my model:

function uploadsinglepicture($uploadpath){

    $config['upload_path'] =$uploadpath;
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '';
    $config['max_width']  = '';
    $config['max_height']  = '';
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload('userfile'))
    {
        $error = array('error' => $this->upload->display_errors());
        print_r($error);
        if($this->input->post('id') == ''){
            $insertion['image'] = '';
        }
        //$this->load->view('upload_form', $error);
    }
    else{
        $data = array('upload_data' => $this->upload->data());
        $insertion['image'] = $data['upload_data']['file_name'];
    }

    $image = $insertion['image'];
    return $image;
}

This is how I access the function in controller:

if(!empty($this->input->post())){
                $path= base_url().'assets/front/img';
                $this->general->uploadsinglepicture($path);
                redirect(base_url().'admin/home/index/sliderupated');
}

but the error I get is:

Array ( [error] => The upload path does not appear to be valid. )

If I print $path, this is what I get

http://localhost/site/assets/front/img/

and that opens in the browser as real path. My code in view is as below

<form  method="post" enctype="multipart/form-data" action ="<?=base_url()?>admin/home/index" >
    <label>Upload Picture </label>
    <input type='file'  name='userfile' />
    <input type="hidden" name="updateimage">
    <input type="submit" class="btn btn-primary pull-right" />
</form>

How can I fix the error?

  • 写回答

3条回答 默认 最新

  • dongqiao3833 2018-03-17 04:42
    关注

    please update this line,

    from ,  $path= base_url().'assets/front/img'; 
    
    to,     $path= FCPATH.'assets/front/img';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?