Codeigniter file upload not working

22,855

At your PHP change

$this->upload->do_upload()

to

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

where "add_1" is your input name attribute.

Codeigniter UPLOAD library docs

P.S. At your HTML the Label attribute for="" is targeting input ID so you have to add id to your input.

Share:
22,855
Dinuka Thilanga
Author by

Dinuka Thilanga

I was software engineer at eMarketingeye. Now i am Senior Software engineer at eFutures.

Updated on February 08, 2020

Comments

  • Dinuka Thilanga
    Dinuka Thilanga about 4 years

    I write code for upload a image file. But it always show You did not select a file to upload. This is my code.

    view

    <?php echo form_open_multipart('template/advertisement', array('id' => 'template-add-form', 'class' => 'form-horizontal')); ?>
        <?php echo form_fieldset('Add Advertisement', array('class' => '')); ?>
        <div class="control-group">
            <label class="control-label" for="add_l">Left Advertisement </label>
            <div class="controls">
                <input type="file" name="add_l"/>
            </div>
        </div>  
        <div class="control-group">
            <div class="controls">
                <input type="submit" name="add" value="Update Advertisement" class="btn btn-primary" /> 
            </div>
        </div>  
        <?php echo form_fieldset_close(); ?>
    <?php echo form_close(); ?>
    

    controller

    public function advertisement()
        {
            $headerData = array();
            $headerData['title'] = ucfirst('Advertisement');
    
            $data = array();
    
            if ($this->input->post() !== FALSE) {   
                $config = array();
                $config['upload_path'] = './images/add';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '100';
                $config['max_width'] = '1024';
                $config['max_height'] = '768';
                $config['max_filename'] = '100';
    
                $this->load->library('upload', $config);
    
                if ($this->upload->do_upload()) {
                    $data['message'] = $this->upload->data();                       
                } else {
                    $data['error'] = $this->upload->display_errors('<div class="alert alert-error">', '</div>');                
                }
            }
    
            $this->load->view('template/header.php', $headerData);
            $this->load->view('template/advertisement.php', $data);
            $this->load->view('template/footer.php');       
        }
    

    Please help me.