当前位置:首页 > 技术 > 正文内容

Discuz X3.4文章和帖子图片存储阿里云OSS远程附件记录

Lavfun2年前 (2022-05-23)技术5136

首先,站点比较小但却很重要,又有快速访问的要求,又不想花钱买付费版插件,所以就自己想办法手动改一下图片存储OSS以达到要求,以下是手动更改过程记录。

再次提醒:以下操作有风险,数据无价!记得备份网站和数据库!另外,本文前提是阿里云OSS要提前购买开通,再添加相关bucket,绑定CDN加速域名等,以及OSSFS工具挂载使用等,这些可以自己在网上找教程。


1、打开OSS Browser,在之前创建好的bucket里创建需要的目录,我创建的有:/data/attachment/,以及/template/PC模版/、/template/手机模版/等几个目录,以方便将相关目录复制过来存储;

2、使用OSSFS工具挂载的方式,把Discuz的“/data/attachment/”目录下的“portal”和“forum”两个目录及里面的所有图片复制到OSS的“/data/attachment/”目录下粘贴;把PC和手机模版目录下的“Icon”和“image”两个目录及里面的所有文件分别复制到OSS的“/template/PC模版/”、“/template/手机模版/”目录下粘贴,这样文章、帖子、模板三个方面的图片全部转移到了OSS;

3、设置Discuz后台的远程附件:管理后台——全局——上传设置——远程附件,先启用,再设置“远程访问URL”为“https://OSS加速域名或绑定的CDN域名/data/attachment”,之后点“提交”;然后再关闭远程附件,点“提交”;


20220523113857.png


4、使用下列SQL数据表命令更改数据库中图片附件为远程附件;

注意:自己的表前缀,下列默认的是pre;命令中:remote=0为本地附件,remote=1为远程附件,以后想改回来时,要全部设置为0;


更改帖子图片:

update pre_forum_attachment_0 set remote=1 where remote=0;
update pre_forum_attachment_1 set remote=1 where remote=0;
update pre_forum_attachment_2 set remote=1 where remote=0;
update pre_forum_attachment_3 set remote=1 where remote=0;
update pre_forum_attachment_4 set remote=1 where remote=0;
update pre_forum_attachment_5 set remote=1 where remote=0;
update pre_forum_attachment_6 set remote=1 where remote=0;
update pre_forum_attachment_7 set remote=1 where remote=0;
update pre_forum_attachment_8 set remote=1 where remote=0;
update pre_forum_attachment_9 set remote=1 where remote=0;


更改文章图片:

update pre_portal_article_title set remote=1 where remote=0;
update pre_portal_attachment set remote=1 where remote=0;
update pre_portal_topic_pic set remote=1 where remote=0;


更改相册图片:【相册表中的remote取值还有一种情况为remote=2(论坛附件图片保存到相册)】

update pre_home_pic set remote=remote+1;


远程转到本地:后台关闭远程附件设置,将附件移动到本地服务器的 data/attachment目录后执行下列sql语句即可:

update pre_forum_attachment_0 set remote=0 where remote=1;
update pre_forum_attachment_1 set remote=0 where remote=1;
update pre_forum_attachment_2 set remote=0 where remote=1;
update pre_forum_attachment_3 set remote=0 where remote=1;
update pre_forum_attachment_4 set remote=0 where remote=1;
update pre_forum_attachment_5 set remote=0 where remote=1;
update pre_forum_attachment_6 set remote=0 where remote=1;
update pre_forum_attachment_7 set remote=0 where remote=1;
update pre_forum_attachment_8 set remote=0 where remote=1;
update pre_forum_attachment_9 set remote=0 where remote=1;

update pre_portal_article_title set remote=0 where remote=1;
update pre_portal_attachment set remote=0 where remote=1;
update pre_portal_topic_pic set remote=0 where remote=1;

update pre_home_pic set remote=remote-1;


5、模板图片更改:

先在相关模板管理插件中更改图片路径,路径前面加上OSS加速域名或绑定的CDN域名即可;

修改相关模板文件里相关图片的路径,方法同上;

修改管理后台——模板——编辑——扩展图片目录 {STYLEIMGDIR}的路径,方法同上;



6、管理后台更新所有缓存,清空浏览器缓存,刷新页面后按F12查看图片链接地址,是不是已经变成了所设置的OSS加速域名或CDN域名呢,搞定收工!

7、如果全部设置完以后,手机版帖子列表和帖子内容不显示远程附件图片,那通常是手机模板问题,需要联系模板开发者来进行修改适配,要修改的手机模板文件有:discuzcode.php、forumdisplay_list.php、guide_list_row.php等等;

8、门户文章列表缩略图的图片是可以自动转成远程附件图片的,门户文章里上传的图片可能无法转成远程附件图片,或者手动修改上传图片的地址;而通过帖子转成文章所带的帖子图片是可以自动转为远程附件的;

9、后续上传的图片仍然是本地附件,需要手动同步或OSSFS同步到OSS里并更改数据库中remote值为1来改为远程附件,数据量不大时,可以定期进行操作即可。



声明:本文是本站原创内容,转载请注明出处!!!否则勿转!!!

扫描二维码推送至手机访问。

版权声明:本文由 声光视趣 - lavfun.com 发布,如需转载请注明出处。

本文链接:https://www.lavfun.com/technical-forum/63.html

分享给朋友:

相关文章

BBCode编辑器常用代码记录

首行缩进2个汉字: [p=null, 2, left]条目内容[/p] [indent]被缩进的内容[/indent] 设定图片显示大小 [img]图片链接[/img] [img=宽度,高度]图片链接[/i...

Discuz手机模版不支持有序列表和无序列表的修改方法

有序列表:条目内容1;条目内容2;条目内容3...无序列表:条目内容1;条目内容2;条目内容3...这两种列表对于文本排版来说非常重要,可以将很多条目列的很清楚,看起来整齐划一,一目了然,本人非常喜欢使用,但很多dz手机模版都不支持,编辑好...

Linux系统下DiscuzQ换了服务器后图片加载不正常解决办法

Linux系统dzq要创建软链接,命令如下:ln -s /www/wwwroot/dzq/storage/app/public /www/wwwroot/dzq/public/storage注意:命令中/www...

解决百度ueditor支持iframe框架页面的视频播放问题

新下载的ueditor 增加了xss 安全过虑,把iframe过滤了,导致发表的文章包含的视频播放功能被限制了。说明:新版本ueditor要修改 xss过滤白名单 修改配置文件ueditor.config.js ...

解决phpcms不支持iframe视频播放的问题

找到文件:phpcms\libs\functions\global.func.php,如下代码:/**  * 转义 javascript 代码标记  *  * @p...