20 January 2021

How to upload file in codeigniter?

Upload file in Codeigniter?


Paste this code in controller

if($this->input->post('upload_file'))

{

$config['upload_path']          = 'uploads';

                $config['allowed_types']        = 'gif|jpg|png';

               // $config['max_size']             = 100;

               // $config['max_width']            = 1024;

               // $config['max_height']           = 768;


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

// $upload_data = $this->upload->data('file_name'); 

                if ( ! $this->upload->do_upload('files'))

                {

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


                        //$this->load->view('upload', $error);

echo 'FIle Error';

                }

                else

                {

                         $data = array('upload_data' => $this->upload->data());


                       // $this->load->view('upload', $data);

echo 'FIle Uploaded Successfully';

$upload_name = $this->upload->data('file_name');

                } 

}

Paste this code in View

<div class="user_update_form">

<form method="post" action="" enctype="multipart/form-data" />

<?php echo validation_errors(); ?>  

<?php //echo $error; ?>  

<?php echo form_open_multipart('upload/do_upload');?>

<h1 class="register_lable">Upload Files</h1>

<label>Files</label>

<input type="file" class="input_field" name="files" value="">

<input type="submit" name="upload_file" class="upload_file" value="Update">


</form>

</div>

No comments:

Post a Comment

How to create youtube videos slider with play and pause option in wordpress?

Create youtube videos slider with play and pause option in wordpress youtube videos slider Use this shortcode:- [punjab_today] function my_...