【发布时间】:2018-04-10 06:40:06
【问题描述】:
我的 Laravel 版本是 5.6,PHP 是 7。 我在互联网上找到了一些上传示例,但大多数都不起作用。 有没有人可以给我一个完整的例子? 我在网上找到了一个类似的案例。 Laravel 5.6 Excel and CSV import export using maatwebsite example
不幸的是,它也不起作用。
这是我的源代码。 刀片.php
<form class="form-upload" method="POST" action="{{url('/excelUpload')}}" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="file">excel upload</label>
<input type="file" id="file" name="ex_file">
<p class="help-block">!!!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default">cancel</button>
<button type="submit" class="btn btn-primary" id="upload_f">submit</button>
controller.php
public function excelUpload(Request $request){
if($request->hasFile('StudentUploadSample')){
return "yes i have a file";
}
return "nofile";
}
但是,结果总是显示“nofile”。 我没有使用任何“use”。我应该使用一些东西吗? 网页上的示例也没有使用任何“use”。 另外,我看了一些网站说文件会放在storage文件夹下,但是在storage文件夹下找不到我的文件“StudentUploadSample.xlsx”。
有没有人可以给我一个完整的例子或者如何解决这个问题?
【问题讨论】:
-
它将返回“nofile”,因为您的输入名称与您的请求不同。您的输入名称是
ex_file,但您请求的是StudentUploadSample。它将返回“nofile” -
投票赞成关闭,因为它有拼写错误。您应该使用您的文件名
StudentUploadSample或在ex_file上致电hasFile