Laravel存储在共享主机上部署后停止工作

mm9b1k5b  于 2023-06-25  发布在  其他
关注(0)|答案(3)|浏览(73)

当我试图改变用户配置文件头像在localhost它的工作,但当我尝试共享主机它不工作。请检查我的家庭控制器代码

public function upload(Request $request)
    {
        $validatedData = $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
           ]);
        if($request->hasFile('image')){
            $filename = $request->image->getClientOriginalName();
            $unique_name = md5($filename. time());
            $request->image->storeAs('images',$unique_name,'public');
            Auth()->user()->update(['image'=>$unique_name]);
        }
        return Redirect('user/profile')->with("success","Profile image successfully changed!");
    }
xhv8bpkk

xhv8bpkk1#

默认情况下,您的图像将转到storage,您可以通过修改config/filesystems.php将其更改为public,如下所示:

'disks' => [
   'public' => [
       'driver' => 'local',
       'root'   => public_path() . '/images', // change this to your desired path
       'url' => env('APP_URL').'/public',
       'visibility' => 'public',
    ]
]

然后通过以下方式访问此存储:

Storage::disk('public')->put('filename', $file_content);
fae0ux8s

fae0ux8s2#

请确保你有链接到你的存储,所以运行这个命令

php artisan storage:link
qvtsj1bj

qvtsj1bj3#

Your images are going to storage by default you can change it to public by modifying config/filesystems.php like this:

'disks' => [
   'public' => [
       'driver' => 'local',
       'root'   => public_path() . '/images', // change this to your desired path
       'url' => env('APP_URL').'/public',
       'visibility' => 'public',
    ]
]

相关问题