已解决 - Laravel 5.8 在另一个项目中保存文件和图像并检索它

SOLVED - Laravel 5.8 Save file and image in another project and retrieve it

我在 laravel 5.8 中有两个项目。 在 sub1.domain.com 中排名第一 第二名 sub2.domain.com

我使用 sub2 保存图像和文件。 我需要查看sub2和sub1的图片和文件。

共享图像和文件的最佳目录存储在哪里?

我有共享主机。

谢谢。

更新 - 已解决

I have changed my filestystem config in this mode:

        'public' => [
            'driver' => 'local',
            // 'root' => public_path() . '/uploads',
            'root' => '/home/xxx/www',
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

现在文件存储在我的每个子域的 "website.com" 的 "public_html" 中。

谢谢大家

The docs state

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 in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public

假设您的所有图像和文件都可以公开访问,请按照这些说明进行操作。

然后,您可以使用 .env 文件中的值来获取路径,而不是使用 asset('storage/file.txt') 打印出可公开访问的 url,就像"https://sub2.domain.com/images/" 然后只需附加您的文件名即可。

write a custom helper method 允许您指定子域,例如 custom_asset('storage/file.txt', 'sub2')

您可以在 public 文件夹中上传,因为符号 link 很难制作 cpanel

修改你的

filesystems.php
in 
'public' => [
            'driver' => 'local',
            'root' => public_path('app/public/uploads'),
            'url' => env('APP_URL').'/uploads',
            'visibility' => 'public',
        ],

在上面 linke 您的上传路径将是

public/uploads
and 
 \Storage::url('example.png')  to get full image url