用于查看和导入的控制器
public function show(Request $request){
$location=$request->file('import_file');
if($request->hasFile('import_file')){
$data = Excel::selectSheets('Sheet1')->load($request->file('import_file'))->noHeading()->toArray();
$result = array(
'data' =>$data,
'page_header' =>'Review Uploaded file',
'location' =>$location,
);
}
return view('admin.floorsheet.list', compact('result'));
}
在这里,我得到了文件的位置,但它只获取临时位置而不是原始文件路径。
public function store(Request $request)
{
if($request->hasFile('import_file')){
Excel::load($request->file('import_file')->getRealPath(), function ($reader) {
foreach ($reader->noHeading()->first()->toArray() as $key => $row) {
$data['transaction'] = $row[1];
$data['symbol'] = $row[2];
$data['buyer'] = $row[3];
$data['seller'] = $row[4];
$data['quantity'] = $row[5];
$data['rate'] = $row[6];
$data['amount'] = $row[7];
if(!empty($data)) {
DB::table('tbl_floorsheet')->insert($data);
}
}
});
}
$result = array(
'page_header' =>'File Uploaded',
'date' =>date('Y-m-d'),
);
return view('admin.floorsheet.import',compact('result'));
}
我的索引页面
<form class="form-horizontal" method="POST" action="{{ route('/my-admin/floorsheet.show') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<div class="form-group">
<label for="file">Upload Filer</label>
<input type="file" class="form-control" name="import_file" >
<label for="acceptdate">Date</label>
<input type="text" class="form-control" id="operationdate" name="operationdate" value="{{ $result['date'] }}">
</div>
</div>
<div class="clearfix"></div>
<div class="clearfix"></div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="form-group">
<button type="submit" class="btn btn-success">Upload File</button>
<button type="reset" class="btn btn-danger">Reset</button>
</div>
</div>
</form>
我的列表页面
<form class="form-horizontal" method="POST" action="{{ route('floorsheet.store') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<div class="form-group">
<label for="file">Upload Filer</label>
<input type="file" class="form-control" name="import_file" value="{{$result['location']}}">
</div>
<table class="table table-hover table-responsive table-condensed" >
<tr>
<th>S.No</th>
<th>Transcation No.</th>
<th>Symbol</th>
<th>Buyer</th>
<th>Seller</th>
<th>Quantity</th>
<th>Rate</th>
<th>Amount</th>
</tr>
@foreach($result['data'] as $d)
<tr>
@foreach($d as $v)
<td>{{$v}}</td>
@endforeach
</tr>
@endforeach
</table>
</div>
<div class="clearfix"></div>
<div class="clearfix"></div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="form-group">
<button type="submit" class="btn btn-success">Upload File</button>
<button type="reset" class="btn btn-danger">Reset</button>
</div>
</div>
</form>
在这里,我已经成功地在视图页面的表格中显示了 excel 文件。但是在使用查看页面上传文件时,我需要再次浏览文件。现在,我需要上传文件而无需再次浏览。当我在视图页面上使用该值时,它只获取临时文件路径而不是原始文件路径。