【问题标题】:Uploading excel file Laravel上传excel文件Laravel
【发布时间】:2017-01-18 08:20:23
【问题描述】:

我尝试在 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() !!} 

还有我在控制器中的功能:

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"
}

我想我只是得到文件名而不是直接得到文件......

【问题讨论】:

    标签: php excel laravel


    【解决方案1】:

    错误是说file('data') 在这种情况下不是对象。

    我会像Log::debug($request); 一样记录$request 数组,看看你可以访问什么。

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

    【讨论】:

    • 我编辑我的问题。在我的 $request 中,我只有文件的名称,这可能是我无法保存它但我不明白该怎么做的原因......
    • 很高兴你知道了。
    【解决方案2】:

    我找到了解决方案,很简单:我忘记将 'files'=>true 设置为我的表单!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      相关资源
      最近更新 更多