我无法将用户图像上传到我的公共(public)文件夹。文件名生成正确,并将名称保存到我的数据库中,除了 iamge 本身拒绝保存到我的公共(public)文件夹中。我做错了什么?
public function update_avatar(Request $request) {
if($request->hasFile('avatar')) {
$avatar = $request->file('avatar');
$filename = time() . "." . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save(public_path('/uploads/'.$filename)); ==> This is causing me errors
user = Auth::user();
$user->avatar = $filename;
$user->save();
}
最佳答案
The public disk is intended for files that are going to be publicly accessible. By default, the
public
disk uses the local driver and stores these files instorage/app/public
. To make them accessible from the web, you should create a symbolic link frompublic/storage
tostorage/app/public
. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments.To create the symbolic link, you may use the
storage:link
Artisan command:
php artisan storage:link
关于Laravel:如何将图像保存到公共(public)文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710275/