Search code examples
phpcodeignitercodeigniter-3

Codeigniter file upload error: You did not select a file to upload


This is really odd, I tried to check the top suggestions in google that is similar to my issue here but I believe those are not the answers to this. I'm using the default 'userfile'. Can anyone tell me what I'm missing here?

The structure of my form:

<div class="panel-body">
    <?php echo form_open_multipart('register','role="studentForm" class="form-horizontal'); ?>

    <div class="form-group">
        <label for="userfile" class="col-lg-3 col-md-3 col-sm-3 control-label">Profile Picture</label>
        <div class="col-lg-9 col-md-9 col-sm-9">
                <input type="file" name="userfile" size="20" id="userfile">
        </div>
    </div>  
    <button type="submit" class="btn btn-default btn-login-style btn-sm pull-right">Submit</button>
    <?php echo form_close(); ?>
</div>

The structure of my controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller{

    function __construct(){
        parent::__construct();
    }

    function index(){

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

        $this->upload->initialize($config); 



        if(!$this->upload->do_upload()){

            $error = array('error'=>$this->upload->display_errors());

            echo $error['error'];
        }else{

            $uploaded_pic = $this->upload->data();
        }
    }
}

?>

NOTE: 'Upload' library is loaded automatically in autoload.php.


Solution

  • ok i got it. I am missing a quotation " in my class:

    the wrong code:

    <?php echo form_open_multipart('register','role="studentForm" class="form-horizontal'); ?> 
    

    the correction here:

    <?php echo form_open_multipart('register','role="studentForm" class="form-horizontal"'); ?>