我正在使用laravel 5.4并尝试将一些xls格式的银行对帐单上传到服务器。xls文件获取存储为上传到服务器的文件夹
文件正在上传到磁盘上,但不是创建一个excel文件,而是创建一个其中包含.txt文件的目录。
此txt文件包含xls文件的内容。
.
├── 835e9d46-b43d-11e7-ad3c-847beb400c7ebank-statement.xls
│ └── 0qaYUFrYBLfDupI5v1GlUBuU6aVA8ZQTKdCrR90o.txt
└── bd4cb0fa-b43e-11e7-bdc8-847beb400c7ebank-statement.xls
└── 2h2Z5Fy6seJtxxxAsYitZwTfA48XIOIpnc7W58xP.txt
视图文件代码
{{ Form::open(['route' => 'upload-statement', 'class' => 'form-horizontal', 'files' => true]) }}
{{ csrf_field() }}
<div class="form-group{{ $errors->has('statement_file') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">Chose statement file</label>
<div class="col-md-6">
<input autocomplete="off" id="statement_file" type="file" class="form-control" name="statement_file" required autofocus >
@if ($errors->has('statement_file'))
<span class="help-block">
<strong>{{ $errors->first('statement_file') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('ga_code') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">GA Code</label>
<div class="col-md-6">
<input id="ga_code" type="text" class="form-control" name="ga_code" required>
@if ($errors->has('ga_code'))
<span class="help-block">
<strong>{{ $errors->first('ga_code') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-4"></label>
<div class="col-lg-8">
<button class="btn btn-primary" id="uploadbankfileid" name="uploadbankfileid">Upload File</button> </div>
</div>
</form>
在它代表的铜工控制器代码
$statementFile = request()->file('statement_file');
$newFileName = Uuid::uuid1() . "bank-statement." . $statementFile->getClientOriginalExtension();
$originalFileName = $statementFile->getClientOriginalName();
$path = $request->file('statement_file')->store(
'/'.$newFileName, 'bank-statements',['mimeType'=>$statementFile->getClientMimeType(),'mime'=>$statementFile->getClientOriginalExtension()]
);
如何上传文件以及如何创建它? –
尝试用guessClientExtension代替getClientOriginalExtension –
完成但不起作用 – sumit