【问题标题】:How to fix "Call to a member function store() on null"?如何修复“在 null 上调用成员函数 store()”?
【发布时间】:2019-05-16 10:48:10
【问题描述】:

我正在为文件夹设置图像上传选项。是什么原因造成的以及如何解决此错误?

MessageController 中的 PHP

public function store(Request $request)
{
    $request->image->store('comments');
}

HTML

<form action="/api/messages" enctype="multipart/form-data" method="post">
    Select image to upload: 
    <input id="fileToUpload" name="fileToUpload" type="file"> 
    <input name="submit" type="submit" value="Upload Image">
</form>

我期待输出 200,但收到服务器错误 500。

【问题讨论】:

  • 你的文件名在两个地方都不一样
  • 使用这个:request()-&gt;fileToUpload-&gt;store('comments');
  • laravel 5.4 upload image的可能重复

标签: php laravel


【解决方案1】:

我相信您在请求中没有正确引用图像文件。相反,请尝试这样做:

$request->file('fileToUpload')->store('comments');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-28
    • 2020-09-08
    • 2017-04-08
    • 2020-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    相关资源
    最近更新 更多