Laravel文件存储返回tmp文件名

问题描述 投票:0回答:1

简单的问题。我试图从表单帖子中将文件保存到存储。码:

$path = $request->file('image')->store('image');

但是$path作为/tmp/phpCCTWsV回归

如何解决这个问题?

php laravel-5 storage
1个回答
1
投票

提交表单时,所有文件都将保存到tmp文件夹中。然后,您必须将它们保存到存储。例如:

$disk = Storage::disk('local');
$path = '/app/public/images/';
$name = time().'.'.$image->getClientOriginalExtension();
$disk->put(str_replace('/app', '', $path) . $name, $request->file('image'));
$path .= $name; // This file's saved in `/storage/app/app/public/images/` folder
© www.soinside.com 2019 - 2024. All rights reserved.