我尝试在 Laravel 中上传带有表单的 excel 文件,但我遇到了问题:
在非对象上调用成员函数 store()
这是我的代码:
{!! Form::open(['route' => 'choixcol']) !!}
<div class="col-md-4">
{!! Form::file('data', '', ['id' => 'file', 'class' => 'form-control']) !!}
</div>
<div class="col-md-8">
{!! Form::submit("Utiliser ce fichier", array('class' => 'btn btn-info')) !!}
</div>
{!! Form::close() !!}
我在 Controller 中的功能:
public function upload(Request $request) {
$path = $request->file('data')->store('data');
return view('mesures.index');
}
请问怎么解决?
编辑:
在我的 $request 中,我有:
Request {#37 ▼
#json: null
#sessionStore: null
#userResolver: Closure {#231 ▶}
#routeResolver: Closure {#248 ▶}
+attributes: ParameterBag {#39 ▶}
+request: ParameterBag {#38 ▼
#parameters: array:2 [▼
"_token" => "6IPVFkzu8o2jH244y0BwJEqKDqfWrt5pKwMS7Pls"
"data" => "99081D_Pesee2016.xlsx"
]
}
+query: ParameterBag {#45 ▶}
+server: ServerBag {#42 ▶}
+files: FileBag {#41 ▶}
+cookies: ParameterBag {#40 ▶}
+headers: HeaderBag {#43 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/mesures/choix"
#requestUri: "/mesures/choix"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session: Store {#205 ▶}
#locale: null
#defaultLocale: "en"
}
我想我只是得到文件的名称,而不是直接得到文件......
最佳答案
错误是说 file('data')
在这种情况下不是对象。
我会记录 $request
像 Log::debug($request);
这样的数组并查看您可以访问的内容。
https://laravel.com/docs/5.3/requests#storing-uploaded-files
关于php - 上传excel文件Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714383/