S.M_Emamian
S.M_Emamian

Reputation: 17393

How to upload file in codeigniter framework

I would like to upload a picture in codeigniter . but I get this error

unsuccessful= You did not select a file to upload.

My code:

    function uploadImageAvatar(){


        $config = array(
            'upload_path' => "/public_html/assets/Vitrin/Avatars/",
            'allowed_types' => "gif|jpg|png|jpeg|pdf",
            'overwrite' => FALSE,
            'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
            'max_height' => "768",
            'max_width' => "1024"
        );

        $this->load->library('upload', $config);

        if($this->upload->do_upload($_FILES['image_file']['tmp_name']))
        {
            echo "successful";

        }
        else
        {

            echo "unsuccessful=".$this->upload->display_errors();
        }
}

My html:

 <form action="{{base_url().'cp/Users/uploadImageAvatar'}}" method="post" enctype="multipart/form-data" id="upload_form">

            <input name="image_file" type="file" required="true" />

            <input type="submit" value="upload" id="submit-btn" />
</form>

where is i'm wrong ?

Upvotes: 2

Views: 70

Answers (1)

Maninderpreet Singh
Maninderpreet Singh

Reputation: 2587

Change this line

if($this->upload->do_upload($_FILES['image_file']['tmp_name']))

to

if($this->upload->do_upload('image_file'))

Upvotes: 3

Related Questions