Laravel 应用程序托管时将图像保存在 storage/app/ 而不是 storage/app/public 中,但在本地正确保存

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

社区, 我的 Laravel 应用程序有问题, 当在我的应用程序中保存图像时,它在本地工作并将它们保存在正确的目录中,但是,当我将应用程序托管到我的服务器并尝试在线测试应用程序时,它现在将图像保存在 storage/app/ 而不是标准存储/app/public/目录。

我的存储链接已就位,我保存图像的功能也已就位。 这是我的文件系统设置

'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
        'throw' => false,
    ],

例如,让我们看一下保存用户进程(使用livewire)。

$data["image"] = str_replace('public/', '', $this->image->store('users'));
        $data["password"] = Hash::make("password");
        $data['status'] = $data['status'] == 1 ? User::STATUS_ACTIVE : User::STATUS_INACTIVE;

        $this->user->create($data);
        $this->resetFields();
        $this->emit("success", "User-created successfully!");

所以之后生成的 URL 看起来像这样

http://127.0.0.1:8000/storage/users/BYHZwuu03z4HikfcncH5hDdpjdbN7jPaQejbZ0fx.jpg

并显示此图像,

<img src="{{ asset('storage/'.$user->image) }}" height="60px" width="60px" 
 class="rounded-pill">

在线托管时,图像不显示,链接如下所示 http://{baseUrl(隐藏)}/storage/users/eFJ8MLBUcREFlXpJQ5JvTQ4ZfeUYcxzB7Dc8IRy3.jpg

可能是什么问题?

现在我不知道为什么图像不显示,

php crud remote-access laravel-livewire laravel-10
2个回答
0
投票

转到 /root_project/public 文件夹并运行命令: php artisan 存储:链接

希望对您有帮助。


0
投票

也许在主机上您需要创建一个链接来访问文件:

php artisan storage:link

查看更多相关信息这里

© www.soinside.com 2019 - 2024. All rights reserved.