My current CI project is now processing files. I want to download xls | xlsx to the server, and then import the excel file data into the database table.
as the first part, the downloaded file was successful, and I upload files to the uploads folder at the same level of application, system, assets . Now I want to download this file and import this content into the database. I am using PHPExcel to perform this operation
Here is my controller
$this->load->library('phpexcel'); $this->load->library('PHPExcel/iofactory'); $objPHPExcel = new PHPExcel(); $objReader= IOFactory::createReader('Excel2007'); $objReader->setReadDataOnly(true); $objPHPExcel=$objReader->load(BASE_URL().'uploads/Data_Report.xls'); $objWorksheet=$objPHPExcel->setActiveSheetIndex(0); $this->load->model('datas_model'); for($i=2;$i<=77;$i++) { $client_name= $objWorksheet->getCellByColumnAndRow(0,$i)->getValue(); $client_address= $objWorksheet->getCellByColumnAndRow(1,$i)->getValue(); $data_inp=array('name'=>$client_name, 'address'=>$client_address); $this->datas_model->add_data($data_inp); }
and here is my view
<?php echo form_open_multipart('../settings_controller/upload_data/do_upload');?> <div class="custom-file-upload"> <input type="file" id="file" name="userfile" multiple/> </div> <div class="button-container-2"> <button class="btn btn-primary" id="updown-btn" type="submit" style="height:45px;">Upload </button> </div> <?php echo "</form>"?>
when I run it, the Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open http://localhost/myproject/uploads/Data_Report.xls for reading! File does not exist.' error Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open http://localhost/myproject/uploads/Data_Report.xls for reading! File does not exist.' Uncaught exception 'PHPExcel_Reader_Exception' with message 'Could not open http://localhost/myproject/uploads/Data_Report.xls for reading! File does not exist.'
when I put this Data_Report.xls file inside htdocs , it works successfully.
The problem is that im uses BASE_URL (). 'uploads / Data_Report.xls'. but the file physically exists, and I checked by inserting localhost / myproject / uploads / Data_Report.xls into the url and it downloaded successfully.
Any help would be greatly appreciated.
source share