gpt4 book ai didi

php - 获取.dat文件内容php

转载 作者:行者123 更新时间:2023-11-29 20:54:53 28 4
gpt4 key购买 nike

我有一个程序可以上传包含 codeigniter 文本的 .dat 文件。

这是上传表单的代码:

查看

<div class="panel panel-warning">
<div class="panel-heading">
<h3><i class="fa fa-list"></i> Upload</h3>
</div>
<div class="panel-body">
<?php echo form_open_multipart('report/coba_upload');?>
<div class="form-group">
<input type="hidden" class="form-control" name="id">
<input type="file" name="file_1" size="20" class="form-control"/><br /><br />
<button type="submit" name="btn_upload" class="btn btn-primary">UPLOAD</button>
</div>
</form>
</div>
</div>

这是处理上传的 Controller 代码:

function coba_upload(){
$this->load->library('upload');
$file = $_FILES['file_1']['name'];
$file_loc = $_FILES['file_1']['tmp_name'];
$folder = "./upload/honor/";
$this->upload->do_upload("file_1");
if (move_uploaded_file($file_loc, $folder . $file)) {
$handle = fopen("./upload/honor/$file", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
echo $buffer;
}
fclose($handle);
}

} else {
echo 'upload failed';
}
}

这是输入文件(.dat 文件)的示例:

GLC002                                  LABA RUGI KONSOLIDASI                                                       PAGE:   1
BANK XXX AS AT MAY 31, 2016 RUN DATE: 06/06/2016
0788 DIV. XXX

--------------------------------------------------------------------------------------------------------------------------
SANDI NAMA REKENING SALDO VALAS DLM RUPIAH SALDO DALAM RUPIAH SALDO GABUNGAN
--------------------------------------------------------------------------------------------------------------------------
PENDAPATAN

4.1 PENDAPATAN BUNGA 28,012,902.00 28,012,902.00
4.2 PENDAPATAN PROPISI & KOMISI
4.3 KEUNTGN TRANSAKSI SURAT BERHARGA
4.4 KEUNTGN/KRG TRANSAKSI VALAS & DERIVATIF
4.8 PENDAPATAN OPERASIONAL LAINNYA
4.9 PENDAPATAN NON OPERASIONAL 304,282,764.00 304,282,764.00
--------------------------------------------------------------------------------------------------------------------------
TOTAL PENDAPATAN 332,295,666.00 332,295,666.00
--------------------------------------------------------------------------------------------------------------------------

但是输出变成一行

GLC002 LABA RUGI KONSOLIDASI PAGE: 1 BANK NEGARA INDONESIA AS AT MAY 31, 2016 RUN DATE: 06/06/2016 0788 DIV. ORGANIZATIONAL LEARNING -------------------------------------------------------------------------------------------------------------------------- SANDI NAMA REKENING SALDO VALAS DLM RUPIAH SALDO DALAM RUPIAH SALDO GABUNGAN -------------------------------------------------------------------------------------------------------------------------- PENDAPATAN 4.1 PENDAPATAN BUNGA 28,012,902.00 28,012,902.00 4.2 PENDAPATAN PROPISI & KOMISI 4.3 KEUNTGN TRANSAKSI SURAT BERHARGA 4.4 KEUNTGN/KRG TRANSAKSI VALAS & DERIVATIF 4.8 PENDAPATAN OPERASIONAL LAINNYA 4.9 PENDAPATAN NON OPERASIONAL 304,282,764.00 304,282,764.00 -------------------------------------------------------------------------------------------------------------------------- TOTAL PENDAPATAN 332,295,666.00 332,295,666.00 -------------------------------------------------------------------------------------------------------------------------- BEBAN 5.1 BEBAN BUNGA 5.2 BEBAN PROPISI & KOMISI 5.3 BEBAN PENYISIHAN KERUGIAN 6,333,036.01- 6,333,036.01- 5.5 BEBAN ADMINISTRASI DAN UMUM 62,029,442,518.19- 62,029,442,518.19- 5.6 KERUGIAN TRANSAKSI SURAT BERHARGA 5.7 KRG TRX VALAS DAN DERIVATIF 5.8 BEBAN OPERASIONAL LAINNYA 500,000.00- 500,000.00- 5.9 BEBAN NON OPERASIONAL -------------------------------------------------------------------------------------------------------------------------- TOTAL BIAYA 62,036,275,554.20- 62,036,275,554.20- -------------------------------------------------------------------------------------------------------------------------- LABA/RUGI TAHUN BERJALAN 61,703,979,888.20- 61,703,979,888.20- -------------------------------------------------------------------------------------------------------------------------- PT BANK XXX

问题是:

  1. 什么函数可以得到与原始文件相同的输出(不仅仅是一个线)?
  2. 如何根据位置(列和行)获取特定文本并将其转换为数组并插入数据库sql?

很抱歉,如果这个问题太基本了,但我一直被困住并且没有得到我需要的东西。请给我一个解决方案。

感谢您的关注和善意

最佳答案

您也许可以使用

标签

<pre>
<?php echo form_open_multipart('report/coba_upload');?>
</pre>

另一种方法是使用nl2br

<?php echo nl2br(form_open_multipart('report/coba_upload'));?>

关于php - 获取.dat文件内容php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37715958/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com