上传路径似乎无效“。 Codeigniter文件上传

问题描述 投票:4回答:5
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'doc|docx';
        $config['max_size'] = '400';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

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

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

  $this->referral_model->postCVReferralInfo($m_id, $emp_id , $job_id, $name, $age , $gender,$country_id, $mobile, $email, $summary, $workExp, $education, $qualification, $offer, $sb_id);
    header('location:'.$this->config->base_url().'index.php/member/referSuccess');

    exit;



    } ` 

如果我尝试上传doc文件,那么我收到此错误“上传路径似乎无效”。我将路径替换为绝对路径,然后我也收到此错误。请建议我如何解决这个问题

file codeigniter upload
5个回答
12
投票

当调用$this->load->library('upload', $config)时,通常会出现问题,可能是它没有加载配置设置,因此请在加载上载库后添加以下语句。

$this->upload->initialize($config);

5
投票

同样的问题......解决了

$this->upload->initialize($config);

最好不要在$CONFIG['UPLOAD_PATH']中使用.... BASE_URL


1
投票

永远不要在$ CONFIG ['UPLOAD_PATH']中使用base_url(),

记下上传文件夹前面的反斜杠前面的点。因此,您的上传路径应如下所示

 $CONFIG['UPLOAD_PATH'] = './assets/uploads/

0
投票

将您的代码更改为此$config['upload_path'] = 'uploads';


0
投票

更好用:

$config["upload_path"] = $_SERVER['DOCUMENT_ROOT']."/your/desired/location/";

并按以下方式初始化您的配置:

$this->upload->initialize($config);
© www.soinside.com 2019 - 2024. All rights reserved.