Codeigniter – photo upload with codeigniter

codeigniterimagephotoupload

I know there are many tutorials online, but I could not make them work 🙁 maybe something particularly wrong with my system :/

My Controller localpath is:
/localhost/rl/applications/backend/controller/

Controller:

function do_upload()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $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('add_image', $error);
    }   
    else
    {
        $data = array('upload_data' => $this->upload->data());

        $data['id'] = $this->input->post['id_work'];
        $this->load->view('add_image', $data);
    }

}

My View localpath is:
/localhost/rl/applications/backend/view/

View:

echo form_open_multipart('do_upload');  
    <ul class="frm">
        <li><label>File: *</label><input type="file" name="userfile" class="frmlmnt" size="50" /></li>      
        <li><label></label><input type="submit" class="btn" value="Upload" /></li>
    </ul>
 </form>        

Maybe I do something wrong with path

Best Answer

Change your view

echo form_open_multipart('backend/controllername/do_upload');  

and create backend folder inside the controllers folder.

Related Topic