Laravel移动上传的文件 [英] Laravel move uploaded file
本文介绍了Laravel移动上传的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于这样的完整路径来说效果很好
It is working good for full path like this
$file=$request->file('file');
$file->move('C:\xampp\htdocs\modo\images',$file->getClientOriginalName());
但是我不明白为什么它不能用于根文件夹路径:
But i cant understand why it doesnt for root folder path :
$file->move('\modo\images',$file->getClientOriginalName());
推荐答案
您需要使用base_path()
方法.此方法返回到项目根目录的完全限定路径:
You need to use base_path()
method. This method returns the fully qualified path to the project root:
因此,请尝试以下代码:
So in your case try the below code:
$file = $request->file('file');
$file->move(base_path('\modo\images'), $file->getClientOriginalName());
,如果要返回公共目录,请使用:
and if you want to return the public directory then use:
$path = public_path();
有关更多信息,请阅读 Laravel帮助器功能
For more info read Laravel helper functions
这篇关于Laravel移动上传的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文