Here a php script to upload file to database using codeigniter:
$this->load->library('upload');
$config['upload_path'] = 'myfolderupload/';
$config['file_name'] = mktime()."-".$_FILES['path']['name'];
$config['overwrite'] = TRUE;
$config['allowed_types'] = 'doc|docx|jpg|jpeg';
$this->upload->initialize($config);
if(!$this->upload->do_upload("path"))
{
echo $this->upload->display_errors();
}else{
$data_upload = $this->upload->data();
$mydata = array(
'name' => $this->input->post('name'),
'path' => $data_upload["file_name"]
);
$this->Your_model->add_function_in_model($mydata);
}
In the above code the first step is load upload library
$this->load->library('upload');
The second step set your path (this is a place to save a file), in my example i save my file in myfolderupload folder.
$config['upload_path'] = 'myfolderupload/';
The third step is use mktime function, so the file was uploaded to be a unique.
$config['file_name'] = mktime()."-".$_FILES['path']['name'];
The fourth step is set allowed file types
$config['allowed_types'] = 'doc|docx|jpg|jpeg';
The fifth step is initialize config. after that check function ulpoad using do_upload. if correct, the script will run this code
$data_upload = $this->upload->data();
$mydata = array(
'name' => $this->input->post('name'),
'path' => $data_upload["file_name"]
);
$this->Your_model->add_function_in_model($mydata);
Title: How to upload file to database using codeigniter
Posted by faisal
Thanks for reading about How to upload file to database using codeigniter
Posted by faisal
Thanks for reading about How to upload file to database using codeigniter