Sunday, September 22, 2019

Upload file using Codeigniter (Excel)

Assalamualaikum/Hello,

In this post I would like to show how to upload a file using codeigniter.

In Controller


public function add() {

  $config = array(
'upload_path' => "./uploads/excel/",
'allowed_types' => "xls|xlsx",
'max_size' => "5000" 
);
$this->load->library('upload', $config);
if($this->upload->do_upload('userfile'))
{
$data = array('upload_data' => $this->upload->data());
}
else
{
$error = array('error' => $this->upload->display_errors());
echo $this->upload->display_errors();
}
}


Important Factors You Need To Consider:

•File/Directory Permission: You must need to make sure that, where you want the uploaded file to be saved, php has proper write permission on those directories. Generally a ‘755’ or ‘777’ permission works fine.


Enjoy, Hope this post will be benefit for all of you. Thank You.










Sya Ahmad
Programmer in Ministry of Health


No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...