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

时间:2013-05-22 11:11:05

标签: file codeigniter upload

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

7 个答案:

答案 0 :(得分:12)

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

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

答案 1 :(得分:5)

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

Acueill.jTableProduit.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
                super.getTableCellRendererComponent( table, value, false, hasFocus, row, col);
                final int qte = (int) table.getModel().getValueAt(row, 7);
                final int min = (int) table.getModel().getValueAt(row, 8);
                if (qte < min) {
                    setBackground(Color.red);
                } else {
                    setBackground(table.getBackground());
                }
                return this;
            }
        });

最好不要在$this->upload->initialize($config);

中使用.... BASE_URL

答案 2 :(得分:1)

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

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

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

答案 3 :(得分:1)

更好地使用:

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

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

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

答案 4 :(得分:0)

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

答案 5 :(得分:0)

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

library(purrr)
library(dplyr)
map(books, nchar) %>%
    flatten_int %>%
     mean

尝试过去

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

答案 6 :(得分:-2)

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

    **Then add this short code**

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

上传成功