5

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.

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

3 Comments

It didn't work for me :( Can't figure out the exact problem. Checked the folder permissions as well. No Success..
@VishalParkash better make new question in SO with example of your code.. commenting that it's not working won't help you
OK.. But my code looks exactly the same, that's why I thought I should comment otherwise I was creating another question. Anyways.. I am uploading file using the CorePHP style.
0

i recenly got that problem and solve it. you can check is module fileinfo in php already on? if you can access to CPanel, you can go to SOFTWARE TAB then search Select PHP Version, then you can see list of module and check that module fileinfo. and try to upload again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.