7
        $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 文件,则会收到此错误“上传路径似乎无效”。我将路径替换为绝对路径,然后我也收到此错误。请建议我如何解决这个问题。`

4

8 回答 8

13

问题一般在调用时出现$this->load->library('upload', $config),可能是没有加载配置设置,所以在加载上传库后尝试添加如下语句。

$this->upload->initialize($config);
于 2015-01-05T10:03:37.277 回答
7

同样的问题...解决了

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

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

于 2016-05-04T10:08:18.780 回答
2

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

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

 $CONFIG['UPLOAD_PATH'] = './assets/uploads/
于 2017-08-18T15:49:59.990 回答
1

更好的使用:

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

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

$this->upload->initialize($config);
于 2019-02-05T08:17:13.953 回答
0

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

于 2014-10-29T11:33:02.150 回答
0

在根目录中创建一个包含 uplaods 的文件夹,并在控制器中使用以下代码

$config['upload_path'] =  'uploads';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2000;
$config['max_width'] = 1500;
$config['max_height'] = 1500;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('profile_pic')) 
{
   $error = array('error' => $this->upload->display_errors());
}else{
   $data = array('image_metadata' => $this->upload->data());
} 
于 2021-10-23T06:13:17.330 回答
0

我遇到了同样的错误,这是我的代码。

        // Upload Image
        $config['upload_path'] = './uploads';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '7048';
        $config['max_width'] = '7000';
        $config['max_height'] = '7000';

        // Create folder (Uploads) if not exists
        if (!is_dir($config['upload_path'])) {
            mkdir($config['upload_path']);
        }

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

        // Initialize the Upload library with curront $config
        $this->upload->initialize($config);

        $this->upload->do_upload();
        if ($this->upload->do_upload()) {
            $data = array('upload_data' => $this->upload->data());
            $page_image = $_FILES['userfile']['name'];
        } else {
            $errors = array('error' => $this->upload->display_errors());
            $page_image = 'noimage.jpg';
        }

        $this->page_model->create_page($page_image);

        // Set message
        $this->session->set_flashdata('page_created', 'Your page has been created');

        redirect('admin/pages/create');

试着过去

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

加载库后上传

        $this->load->library('upload', $config);
于 2021-03-30T17:54:32.733 回答
-2

**注意这一行:** $this->load->library('upload', $config);

    **Then add this short code**

$this->上传->初始化($config);

上传成功

于 2021-07-23T08:21:31.590 回答