Download Codeigniter file not working

I am writing code to upload an image file. But it always shows. 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.

+5
source share
2 answers

When changing PHP

$this->upload->do_upload()

to

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

where "add_1" is your input name attribute.

Codeigniter UPLOAD Documentation Documents

PS In your HTML, the label attribute for = "" is for entering an input identifier, so you need to add an identifier to your input.

+13
source

. fileinfo php ? CPanel, SOFTWARE TAB, PHP, fileinfo. .

0

All Articles