php - 上传excel文件Laravel

标签 php excel laravel

我尝试在 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')在这种情况下不是对象。

我会记录 $requestLog::debug($request); 这样的数组并查看您可以访问的内容。

https://laravel.com/docs/5.3/requests#storing-uploaded-files

关于php - 上传excel文件Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714383/

相关文章:

php - 统计多值查询

php - 带有文本框的 "other"选择的 html 单选按钮

php - mysql WHERE 语句中的字符串数组值

sorting - Excel VBA - 应用自动过滤器并按特定颜色排序

php - 在 Laravel 5.1 DB 中重命名列的异常

laravel Blade 包含具有相对路径的文件

php - Laravel 4 应用程序中的浏览器缓存问题

string - 是否可以在 Excel 单元格中执行多个彩色文本?

excel - 从网站获取数据的vba代码

php - 如何将文件从 laravel 存储复制到项目目录之外的目录中