laravel 5.3上传文件 [英] laravel 5.3 upload file

查看:61
本文介绍了laravel 5.3上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel 5.3,我想将文件上传到目录.我一直在关注laravel文档来上传文件,例如以下代码:

I'm using laravel 5.3, and i want to upload a file to a directory. i've been following laravel documentation for uploading file, like this code :

public function store(Request $request)
{
    $path = $request->attachment->store('attachment');
}

但出现错误

在字符串上调用成员函数store()

Call to a member function store() on string

以前在laravel 5.2上,我一直使用此代码上传文件,并且可以正常工作

previously on laravel 5.2, i've been use this code for uploading file and it's work

if ($request->hasFile('attachment')) {
    $destination = 'upload/attachment';
    $file = $request->file('attachment');
    $file->move($destination, $file->getClientOriginalName());
}

$filelocation = $destination. "/" .$file->getClientOriginalName();

但是在laravel 5.3中它不起作用,并且出现错误

but in laravel 5.3 it's doesn't work, and i get an error

未定义变量:目的地

Undefined variable: destination

您能帮我解决我的代码有什么问题吗?

can you help what wrong with my code ?

推荐答案

在Larave 5.3中,您可以使用简单的上传文件,如下所示:

In Larave 5.3 you can use simple upload file like this:

$request->file('file')->storePublicly($folderSrc);

这会将您的文件保存到storage/app/public/you-folder-src

This save you file to storage/app/public/you-folder-src

这篇关于laravel 5.3上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆