我有一个提交文件代码,可以将Excel文件上传到我的服务器,然后通过该功能使用它。
这样做:
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";
它给了我这个输出:
加载文件时出错" .xlsx":无法打开 /var/www/html/tools/files/automation/1/.xlsx阅读!文件呢 不存在。
我怀疑它是因为它还没有找到该文件,因为它还没有上传。可能?
答案 0 :(得分:1)
如果您想要按用户或不需要的任何内容上传文件夹在差异文件夹中
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();
}