Laravel 移动上传文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37694337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:24:21  来源:igfitidea点击:

Laravel move uploaded file

imagelaravelupload

提问by Kamran G.

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());

回答by Iftikhar uddin

You need to use base_path()method. This method returns the fully qualified path to the project root:

你需要使用base_path()方法。此方法返回项目根目录的完全限定路径:

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();

For more info read Laravel helper functions

有关更多信息,请阅读Laravel 辅助函数

回答by GONG

You need to do it this way:

你需要这样做:

$file->move(base_path('\modo\images'),$file->getClientOriginalName());