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

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

我在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”中。

谢谢大家。

laravel image file shared
2个回答
1
投票

The docs state

公共磁盘用于要公开的文件无障碍。默认情况下,公用磁盘使用本地驱动程序,将这些文件存储在storage/app/public中。使它们可以从在网络上,您应该创建一个从public/storagestorage/app/public

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

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

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


0
投票

您可以在公共文件夹中上载,因为很难建立符号链接

修改ur

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

在上面的链接中您的上传路径将是>>

public/uploads
and 
 \Storage::url('example.png')  to get full image url 
© www.soinside.com 2019 - 2024. All rights reserved.