I have a submit file code that uploads an Excel file to my server and then uses it through the function.
When doing so:
if ($this->upload->do_upload()){
$data = array('upload_data' => $this->upload->data());
$filename = $data['raw_name'];
$fullfilename = $data['orig_name'];
$inputFileName = FCPATH."files/automation/1/$filename.xlsx";
$inputFileNameNew = FCPATH."files/automation/1/$filename-new.xlsx";
It gives me this output:
Error loading file ".xlsx": Could not open /var/www/html/tools/files/automation/1/.xlsx for reading! File does not exist.
Where I suspect it's because it hasn't found the file because it wasn't uploaded yet. Could be?
if you want to upload a file in diferents folders by user or whatever you need to do this
public function upload_f(){
$config['upload_path'] = FCPATH . '/files/automation/' . $id . '/';
$config['allowed_types'] = 'xls|xlsx';
$this->load->library('upload', $config);
if( ! $this->upload->do_upload()){
$this->session->set_flashdata('upload-no', $this->upload->display_errors());
}
else{
$this->_read_file(FCPATH . '/files/automation/' . $id . '/' . $this->upload->file_name);
}
}
private funtion _read_file( $file ){
$this->load->library('excel');
$this->load->library('table');
$file = str_replace('//', '/', $file);
$objPHPExcel = PHPExcel_IOFactory::load($file);
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
$lastRow = $objPHPExcel->getActiveSheet()->getHighestRow();
foreach ($cell_collection as $cell) {
$column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row == 1) {
$header[$row][$column] = $data_value;
}
else{
$arr_data[$row][$column] = $data_value;
}
}
$this->table->set_heading('ID', 'value1', 'value2');
for($i = 2; $i <= $lastRow; $i++){
$_table= array($i, $arr_data[$i]['A'], $arr_data[$i]['B']);
$this->table->add_row($_table);
}
echo $this->table->generate();
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments