From 217958b0dd3c311e84260bf759dbfbda2cc192e3 Mon Sep 17 00:00:00 2001 From: devil Date: Sun, 23 Aug 2020 20:42:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=84=E4=BB=B6url=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/ResourcesService.php | 18 ++++++++++++++++-- config/shopxo.php | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/application/service/ResourcesService.php b/application/service/ResourcesService.php index ba24fb5ee..a8f6e27d7 100755 --- a/application/service/ResourcesService.php +++ b/application/service/ResourcesService.php @@ -34,16 +34,30 @@ class ResourcesService */ public static function ContentStaticReplace($content, $type = 'get') { + // 配置文件附件url地址 + $attachment_host = config('shopxo.attachment_host'); + if(empty($attachment_host)) + { + $attachment_host = substr(__MY_PUBLIC_URL__, 0, -1); + } + $attachment_host_path = $attachment_host.'/static/'; + + // 根据类型处理附件地址 switch($type) { // 读取内容 case 'get': - return str_replace('src="/static/', 'src="'.__MY_PUBLIC_URL__.'static/', $content); + return str_replace('src="/static/', 'src="'.$attachment_host_path, $content); break; // 内容写入 case 'add': - return str_replace(array('src="'.__MY_PUBLIC_URL__.'static/', 'src="'.__MY_ROOT_PUBLIC__.'static/'), 'src="/static/', $content); + $search = [ + 'src="'.__MY_PUBLIC_URL__.'static/', + 'src="'.__MY_ROOT_PUBLIC__.'static/', + 'src="'.$attachment_host_path, + ]; + return str_replace($search, 'src="/static/', $content); } return $content; } diff --git a/config/shopxo.php b/config/shopxo.php index c4c6bffb0..db63b474a 100755 --- a/config/shopxo.php +++ b/config/shopxo.php @@ -57,7 +57,7 @@ return [ // 导航缓存信息 'cache_navigation_key' => 'cache_navigation_data_', - // 附件host, 数据库图片地址以/static/...开头 + // 附件host、最后不要带/斜杠结尾, 数据库图片地址以/static/...开头 'attachment_host' => defined('__MY_PUBLIC_URL__') ? substr(__MY_PUBLIC_URL__, 0, -1) : '', // 应用商店地址