gpt4 book ai didi

laravel - undefined variable : request

转载 作者:行者123 更新时间:2023-12-03 09:45:12 25 4
gpt4 key购买 nike

当我尝试上传文件时,它显示错误:

Undefined variable: request



这是我使用它的地方:
上传 Controller :
if($request->hasFile('file')){
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('app.fileDesinationPath').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file->getRealPath()));

}
return redirect()->to('/upload');

这里有什么问题?

最佳答案

添加 Request $request函数中的参数。例子:

public function yourFunction(Request $request)
{
if($request->hasFile('file')){
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('app.fileDesinationPath').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file->getRealPath()));

}
return redirect()->to('/upload');
}

请仔细阅读文档: http://laravel.com/docs

你也可以在这里观看 Laravel 教程: http://laracasts.com

关于laravel - undefined variable : request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41630393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com