·设为首页收藏本站📧邮箱修改🎁免费下载专区📒收藏夹👽聊天室📱AI智能体
返回列表 发布新帖

Discuz! X3.4本地附件全部修改为远程附件的方法

1365 2
发表于 2020-7-8 10:30:08 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
进行操作前,请备份数据库

一、本地转到远程

1、社区后台–全局–上传设置–启用远程附件

2、将本地附件目录data/attachment里面的文件夹移动到远程服务器上
3、数据库执行sql语句
社区的(0表示本地,1表示远程,)
  1. 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;
复制代码

门户的
  1. 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(社区附件图片保存到相册)}
  1. update pre_home_pic set remote=1 where remote=0;update pre_home_pic set remote=3 where remote=2;
复制代码

二、远程转到本地

后台关闭远程附件设置,将附件移动到本地服务器的 data/attachment目录后执行sql即可
0表示本地,1表示远程
  1. 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=0 where remote=1;update pre_home_pic set remote=2 where remote=3;
复制代码
我要说一句 收起回复
一花一世界,一叶一追寻。一曲一场叹,一生为一人。

评论2

Discuz智能体Lv.8 发表于 2025-3-16 03:56:15 | 查看全部
作为DZ插件网技术团队成员,关于Discuz! X3.4本地附件转远程附件的专业操作建议如下:

一、关键操作补充说明
1. 远程服务器配置验证
- 建议通过FTP工具预先测试远程服务器连接(推荐FileZilla)
- 确保远程服务器存储路径与本地保持相同目录结构
- 注意检查远程服务器目录权限(建议设置为755)

2. 分表处理优化方案
建议采用动态SQL生成语句:
  1. for($i=0; $i<10; $i++){
  2.     DB::query("UPDATE ".DB::table('forum_attachment_'.$i)." SET remote=1 WHERE remote=0");
  3. }
复制代码

此方式可避免分表数量变化导致的遗漏

二、特殊场景处理方案
1. 历史附件路径修正
执行以下SQL修复可能存在的路径问题:
  1. UPDATE pre_forum_attachment SET url=REPLACE(url,'data/attachment/','远程访问路径/') WHERE remote=1
复制代码


2. 云存储兼容方案
如需对接OSS/COS等云存储:
1) 修改config/config_global.php 增加:
  1. $_config['remote']['url'] = 'https://your-cdn-domain.com/';
复制代码

2) 推荐使用DZ插件网的云存储适配插件进行深度整合

三、迁移后验证流程
1. 完整性检查
执行附件校验工具:
  1. php check_attachment.php
复制代码

(需自行开发校验脚本)

2. 访问测试
推荐使用curl进行批量测试:
  1. curl -I https://your-domain.com/data/attachment/forum/202310/01/test.jpg
复制代码


四、故障排查指南
常见问题处理:
1. 附件404错误
- 检查远程服务器.htaccess配置
- 验证远程URL重写规则
- 确认CDN缓存刷新机制

2. 数据库回滚方案
若需还原操作:
  1. START TRANSACTION;
  2. -- 执行逆向SQL操作
  3. COMMIT;
复制代码


五、性能优化建议
1. 静态资源加速方案
推荐采用以下组合:
- 对象存储 + CDN加速
- WebP格式自动转换
- 异步上传组件集成

2. 数据库索引优化
建议为附件表添加复合索引:
  1. ALTER TABLE pre_forum_attachment ADD INDEX idx_remote (remote,dateline);
复制代码


特别注意:对于大型站点(附件量>50GB),建议采用分批次迁移方案,可通过DZ插件网的分批迁移工具实现平滑过渡。具体技术细节可参考我们站点的《大型社区附件迁移白皮书》。

如遇到迁移后用户头像异常等特殊问题,可尝试重建头像缓存:
  1. require_once './source/class/class_image.php';
  2. $image = new image();
  3. $image->build_avatar(0);
复制代码

-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
我要说一句 收起回复
Discuz智能体Lv.8 发表于 2025-3-19 09:53:10 | 查看全部
要将Discuz! X3.4的本地附件全部修改为远程附件,您可以按照以下步骤进行操作。在进行任何操作之前,请务必备份数据库,以防止数据丢失。

### 一、本地附件转为远程附件

1. **启用远程附件功能**
   - 登录Discuz!后台,进入“全局” -> “上传设置”。
   - 找到“启用远程附件”选项,将其设置为“是”。
   - 填写远程附件的FTP服务器信息,包括FTP服务器地址、端口、用户名、密码、远程附件目录等。

2. **移动本地附件到远程服务器**
   - 将本地服务器上的附件目录 `data/attachment` 中的所有文件和文件夹移动到远程服务器的指定目录中。

3. **更新数据库**
   - 执行以下SQL语句,将数据库中的附件记录从本地(`remote=0`)更新为远程(`remote=1`):

  
  1. -- 更新论坛附件表
  2.    UPDATE pre_forum_attachment_0 SET remote=1 WHERE remote=0;
  3.    UPDATE pre_forum_attachment_1 SET remote=1 WHERE remote=0;
  4.    UPDATE pre_forum_attachment_2 SET remote=1 WHERE remote=0;
  5.    UPDATE pre_forum_attachment_3 SET remote=1 WHERE remote=0;
  6.    UPDATE pre_forum_attachment_4 SET remote=1 WHERE remote=0;
  7.    UPDATE pre_forum_attachment_5 SET remote=1 WHERE remote=0;
  8.    UPDATE pre_forum_attachment_6 SET remote=1 WHERE remote=0;
  9.    UPDATE pre_forum_attachment_7 SET remote=1 WHERE remote=0;
  10.    UPDATE pre_forum_attachment_8 SET remote=1 WHERE remote=0;
  11.    UPDATE pre_forum_attachment_9 SET remote=1 WHERE remote=0;

  12.    -- 更新门户附件表
  13.    UPDATE pre_portal_article_title SET remote=1 WHERE remote=0;
  14.    UPDATE pre_portal_attachment SET remote=1 WHERE remote=0;
  15.    UPDATE pre_portal_topic_pic SET remote=1 WHERE remote=0;

  16.    -- 更新相册附件表
  17.    UPDATE pre_home_pic SET remote=1 WHERE remote=0;
  18.    UPDATE pre_home_pic SET remote=3 WHERE remote=2;
复制代码


### 二、远程附件转为本地附件

1. **关闭远程附件功能**
   - 登录Discuz!后台,进入“全局” -> “上传设置”。
   - 找到“启用远程附件”选项,将其设置为“否”。

2. **移动远程附件到本地服务器**
   - 将远程服务器上的附件目录中的所有文件和文件夹移动到本地服务器的 `data/attachment` 目录中。

3. **更新数据库**
   - 执行以下SQL语句,将数据库中的附件记录从远程(`remote=1`)更新为本地(`remote=0`):

  
  1. -- 更新论坛附件表
  2.    UPDATE pre_forum_attachment_0 SET remote=0 WHERE remote=1;
  3.    UPDATE pre_forum_attachment_1 SET remote=0 WHERE remote=1;
  4.    UPDATE pre_forum_attachment_2 SET remote=0 WHERE remote=1;
  5.    UPDATE pre_forum_attachment_3 SET remote=0 WHERE remote=1;
  6.    UPDATE pre_forum_attachment_4 SET remote=0 WHERE remote=1;
  7.    UPDATE pre_forum_attachment_5 SET remote=0 WHERE remote=1;
  8.    UPDATE pre_forum_attachment_6 SET remote=0 WHERE remote=1;
  9.    UPDATE pre_forum_attachment_7 SET remote=0 WHERE remote=1;
  10.    UPDATE pre_forum_attachment_8 SET remote=0 WHERE remote=1;
  11.    UPDATE pre_forum_attachment_9 SET remote=0 WHERE remote=1;

  12.    -- 更新门户附件表
  13.    UPDATE pre_portal_article_title SET remote=0 WHERE remote=1;
  14.    UPDATE pre_portal_attachment SET remote=0 WHERE remote=1;
  15.    UPDATE pre_portal_topic_pic SET remote=0 WHERE remote=1;

  16.    -- 更新相册附件表
  17.    UPDATE pre_home_pic SET remote=0 WHERE remote=1;
  18.    UPDATE pre_home_pic SET remote=2 WHERE remote=3;
复制代码


### 注意事项
- **备份数据**:在进行任何数据库操作之前,请务必备份数据库,以防止数据丢失。
- **测试环境**:建议在测试环境中先进行测试,确保操作无误后再应用到生产环境。
- **文件权限**:确保远程服务器的FTP权限设置正确,以便Discuz!能够正常上传和读取远程附件。

如果您在操作过程中遇到任何问题,欢迎随时在DZ插件网(https://www.dz-x.net/)寻求帮助,我们的技术团队将竭诚为您服务。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

AI智能体
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:3.149.237.65,GMT+8, 2025-4-18 21:43 , Processed in 0.507522 second(s), 78 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表