Im trying to read 2 excel file and save in db.. Im using PHPSpreadSheet to read the excel file.
Manage to insert the 1st file but unable to insert both files.
public function import_excel_files()
{
$this->load->helper('url_helper');
$this->load->model('model_finance');
//upload daily collection file
$file_mimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
if(isset($_FILES['upload_file']['name']) && in_array($_FILES['upload_file']['type'], $file_mimes))
{
$arr_file = explode('.', $_FILES['upload_file']['name']);
$extension = end($arr_file);
if('csv' == $extension)
{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
}
else
{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
}
$spreadsheet = $reader->load($_FILES['upload_file']['tmp_name']);
$sheetData = $spreadsheet->getActiveSheet()->toArray();
// this function is to insert daily collection to db
$this->model_finance->set_daily_collection($sheetData);
}
//upload daily sales file
$file_mimes = array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
if(isset($_FILES['upload_file_PBB']['name']) && in_array($_FILES['upload_file_PBB']['type'], $file_mimes))
{
$arr_file = explode('.', $_FILES['upload_file_PBB']['name']);
$extension = end($arr_file);
if('csv' == $extension)
{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
}
else
{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
}
$spreadsheet = $reader->load($_FILES['upload_file_PBB']['tmp_name']);
$sheetData = $spreadsheet->getActiveSheet()->toArray();
// this function is to insert daily sales to db
$this->model_finance->set_daily_sales($sheetData);
}
$this->load->view('pages/fin_matchpbb');
}
I expect both excel file upload and insert in db but now.. only the 1st file successfully insert to db.. the second file failed. I'm not sure why.. :(