【问题标题】:The upload path does not appear to be valid”. Codeigniter file upload上传路径似乎无效”。 Codeigniter 文件上传
【发布时间】:2013-05-17 09:57:42
【问题描述】:
        $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 文件,则会收到此错误“上传路径似乎无效”。我将路径替换为绝对路径,然后我也收到此错误。 请建议我如何解决这个问题。`

【问题讨论】:

  • 你的上传文件夹在哪里???
  • uploads 文件夹在主文件夹内(应用程序文件夹、图像文件夹等放在主文件夹内)
  • 确保目录是可写的。上面设置了什么chmod?
  • 目录是可写的。
  • CodeIgniter 将仅在 $config['upload_path'] 为空白(不是)或 php 命令 is_dir(upload_path) 返回 false 时返回该错误消息。所以这表示找不到定义的路径。检查以确保“上传”文件夹与主 index.php 文件位于同一目录中,并且目录名称大小写相同(即上传而不是上传)

标签: file codeigniter upload


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    同样的问题...解决了

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

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

    【讨论】:

    • 是的,就我而言,BASE_URL 也是问题
    【解决方案3】:

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

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

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

    【讨论】:

      【解决方案4】:

      更好的使用:

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

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

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

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

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

                  // 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);
          

          【讨论】:

            【解决方案7】:

            在根目录下创建一个包含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());
            } 
            

            【讨论】:

              【解决方案8】:

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

                  **Then add this short code**
              

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

              上传成功

              【讨论】:

              猜你喜欢
              • 2018-09-02
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-12-28
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-10-13
              相关资源
              最近更新 更多