baijunyao / laravel-bjyblog

Laravel v9 blog
https://baijunyao.com/docs/laravel-bjyblog
MIT License
526 stars 201 forks source link

Mirror of Gitee I1KGFY #150

Open baijunyao opened 4 years ago

baijunyao commented 4 years ago

https://gitee.com/baijunyao/laravel-bjyblog/issues/I1KGFY

Edward1108 commented 4 years ago

水印没有生效的问题还是没有找到,我在本地环境测试是好的,正式环境不行。正式环境的gd扩展已安装,FreeType也有 正式环境:app/Support/helpers.php 33行代码执行成功;vendor/intervention/image/src/Intervention/Image/Image.php 156行代码执行成功。

Edward1108 commented 4 years ago

已解决。问题是:需要清除浏览器缓存,刷新后就显示了

baijunyao commented 4 years ago

@Edward1108 针对第 3 个问题;上传图片到 OSS 是用于备份? 还是准备在网页中引用 OSS 的图片链接?

Edward1108 commented 4 years ago

@baijunyao 希望项目里上传的附件都可以保存到oss中。我目前项目是使用的Thinkphp6,以下是我的配置文件,仅供参考。

.env [FILESYSTEM] DRIVER = aliyun_dev

config/filesystem.php <?php return [ // 默认磁盘 'default' => env('filesystem.driver', 'local'), // 磁盘列表 'disks' => [ 'local' => [ 'type' => 'local', 'root' => app()->getRuntimePath() . 'storage', ], 'public' => [ // 磁盘类型 'type' => 'local', // 磁盘路径 'root' => app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 'url' => '/storage', // 可见性 'visibility' => 'public', ], 'aliyun_dev' => [ 'type' => 'aliyun', 'accessId' => '', 'accessSecret' => '', 'bucket' => '', 'endpoint' => 'oss-cn-beijing.aliyuncs.com', 'url' => '',//不要斜杠结尾,此处为URL地址域名。 ], 'aliyun_prod' => [ 'type' => 'aliyun', 'accessId' => '', 'accessSecret' => '', 'bucket' => '', 'endpoint' => 'oss-cn-beijing-internal.aliyuncs.com', 'url' => '',//不要斜杠结尾,此处为URL地址域名。 ], ], ];

这个方法是根据当前配置项自动构造文件的访问路径 /**

baijunyao commented 4 years ago

格式化上面的代码:

'disks' => [ 
    'local' => [ 
        'type' => 'local', 
        'root' => app()->getRuntimePath() . 'storage', 
    ], 
    'public' => [ // 磁盘类型 
        'type' => 'local', // 磁盘路径 
        'root' => app()->getRootPath() . 'public/storage', // 磁盘路径对应的外部URL路径 
        'url' => '/storage', // 可见性 
        'visibility' => 'public', 
    ], 
    'aliyun_dev' => [ 
        'type' => 'aliyun', 
        'accessId' => '', 
        'accessSecret' => '', 
        'bucket' => '', 
        'endpoint' => 'oss-cn-beijing.aliyuncs.com', 
        'url' => '',//不要斜杠结尾,此处为URL地址域名。 
    ], 
    'aliyun_prod' => [ 
        'type' => 'aliyun', 
        'accessId' => '', 
        'accessSecret' => '', 
        'bucket' => '', 
        'endpoint' => 'oss-cn-beijing-internal.aliyuncs.com', 
        'url' => '',//不要斜杠结尾,此处为URL地址域名。 
    ], 
], 
/** 
* 域名连接 
*
* @param $str 
* @return string 
*/ 
public static function domainConnect($str) { 
    if(empty($str)){
        return ''; 
    } 

    $type   = config('filesystem.disks.'.env('filesystem.driver').'.type'); 
    $domain = config('filesystem.disks.'.env('filesystem.driver').'.url'); 

    if(empty($domain)){ 
        return ''; 
    } 

    if($type == 'local'){ 
        $domain = app()->request->server('HTTP_HOST').$domain; 
    } 

    if (Str::endsWith($domain, ['/'])) { 
        $domain = substr($domain, 0, -1); 
    } 

    $str = Str::startsWith($str, ['/']) ? $str : '/' . $str; 

    return $domain . $str; 
}
baijunyao commented 4 years ago

@Edward1108 功能已经开发完成 merge 到 master 了; 可以拉取最新的代码使用;
需要先配置 OSS ;
image
如果需要使用 OSS 的链接;可以在这里配置域名;
image

另外可以运行 php artisan file:sync-to-oss 命令把本地之前上传的文件同步到 OSS ;

Edward1108 commented 4 years ago

@baijunyao 好的,谢谢。辛苦了