0
votes

I'm new to using the file upload class in CodeIgniter. I haven't been able to get their sample script to work. I set the permissions of the uploads folder to 755 like they instructed. I keep getting an error that I did not select a file even though if I echo the $_POST the file is there. Here is my code. Can someone help?

    $config['upload_path'] = './uploads';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '10000';
    //$config['max_width']  = '1024';
    //$config['max_height']  = '768';

    $file = $this->input->post('file');

    //echo 'file = ' . $file;

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

    if (!$this->upload->do_upload($file))
    {
        $error = array('error' => $this->upload->display_errors());
        echo '<pre>'; print_r($error); echo '</pre>';
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        $this->load->view('upload_success', $data);
    }   
1

1 Answers

1
votes

In the $this->upload->do_upload you need to specify the name of the upload input not the post value of the file. So for the input below.

<input type="file" name="upload" />

You would put

$this->upload->do_upload("upload");