diff --git a/application/service/ResourcesService.php b/application/service/ResourcesService.php index ba24fb5ee109613a4e98fdb5bcbdda403f3d83e1..a8f6e27d795a90edbf39e9bc829c17e212456ed9 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 c4c6bffb0064708f5d488190f43e4606a82db14b..db63b474a264522678468f29a0dd1f524b13ac6e 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) : '', // 应用商店地址