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 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题