无法打开Empty_import_sheet.xlsx进行阅读!文件不存在

时间:2019-07-10 10:42:47

标签: codeigniter

我要在Web应用程序中导入excel文件,并检查用户在数据库中excel文件中输入的每一行中是否存在ID。我没有收到任何错误,但是它没有将日志保存在我的数据库中。 检查是否存在也不起作用。

这是我的控制者:

            $user_id = $_GET["user_id"];
            $date = date("Y-m-d H:i:s");

            $config['upload_path']   = './assets/img/import/'; 
            $config['allowed_types'] = 'txt|csv|xlsx|xls';
            $new_name = $_FILES["import_document"]['name'];
            $new_name = $new_name . date('YmdHis');
            $config['file_name'] = $new_name;


            $file_path = "assets/img/import/";
            $status = "1";

            $transaction_class = new TransactionModel;
            $client_class = new ClientModel;

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload('import_document')) {
                $error = array('error' => $this->upload->display_errors());
            }
             else
            { 
                require_once( APPPATH . 'views/excel-report/PHPExcel/Classes/PHPExcel/IOFactory.php');
                $object = PHPExcel_IOFactory::load($new_name);
                foreach($object->getWorksheetIterator() as $worksheet)
                {
                    $highestRow = $worksheet->getHighestRow();
                    $highestColumn = $worksheet->getHighestColumn();
                    for($row=2; $row<=$highestRow; $row++)
                    {
                     $account_id = $worksheet->getCellByColumnAndRow(0, $row)->getValue();
                     $client_id = $worksheet->getCellByColumnAndRow(1, $row)->getValue();
                     $transaction_type = $worksheet->getCellByColumnAndRow(2, $row)->getValue();
                     $payment_method = $worksheet->getCellByColumnAndRow(6, $row)->getValue();
                    }
                 $this->client_class->checkExistLoanCode($account_id);
                    if ($account_id == 0) {
                        echo "<span class='color-red fa fa-close'></span>&nbsp;Account ID: ".$account_id."does not exist.";
                    }$this->client_class->checkExistClientCode($client_code);
                    if ($client_code == 0) {
                        echo "<span class='color-red fa fa-close'></span>&nbsp;Client ID: ".$client_code."does not exist.";
                    }
                    if ($transaction_type == "Deposit" || $transaction_type == "Withdrawal" || $transaction_type == "Repayment") {
                        echo "<span class='color-red fa fa-close'></span>&nbsp;Transaction Type: ".$transaction_type."is not valid.";
                    }
                    if ($payment_method == "Cash" || $payment_method == "Cheque" ) {
                        echo "<span class='color-red fa fa-close'></span>&nbsp;Payment Method: ".$payment_method."is not valid.";
                    }
               }
                $data = array('upload_data' => $this->upload->data()); 
$transaction_class->insertImportTransaction($user_id,$new_name,$file_path,$status,$date);
                }

0 个答案:

没有答案