您现在的位置是:首页 > cms教程 > Discuz教程Discuz教程

discuz模拟批量上传附件发帖的方法

代云2025-07-10Discuz教程已有人查阅

导读discuz 模拟批量上传附件发帖简介对于很多用discuz做资源下载站来说,一个个上传附件,发帖是很繁琐的过程。如果需要批量上传附件发帖,就需要去模拟discuz 上传附件的流程。

discuz 模拟批量上传附件发帖简介对于很多用discuz做资源下载站来说,一个个上传附件,发帖是很繁琐的过程。如果需要批量上传附件发帖,就需要去模拟discuz 上传附件的流程。
插件地址 http://addon.discuz.com/?@uauc_auto_thread.plugin模拟上传discuz 附件逻辑dz附件储存在一个附件索引表pre_forum_attachment 和一系列分表pre_forum_attachment_0-9 里面,具体是哪个分表工具帖子tid而定。
参考discuz 内部实现可以精简为$tableid=substr($tid, -1); //tableid 为附件分表数字 帖子id 附件模拟上传函数根据以上分析,封装为一个单独的函数
/**
*@desc 添加附件函数,具体操作是模拟discuz正常上传附件功能,返回一个附件id
*@param $file 服务器上面的文件路径
*@param $tid 帖子id
*@param $pid post_id
*@param $dirs 文件夹
*@param $attachment_score 积分
*@return 返回附件id
**/
function add_attachment($file,$tid,$pid,$dirs,$attachment_score){
$file_path=$dirs.'\\'.$file;
//后缀
$attachment='/'.md5(rand_str()).".attach";
$new_file_path='./data/attachment/forum'.$attachment;
$uid=1; //暂时设置为管理员
if(copy($file_path,$new_file_path)){
$tableid=substr($tid, -1); // 分表处理逻辑
$attach=array(
'tid' => $tid ,
'pid' => $pid,
'uid' => $uid,
'tableid' => $tableid,
);
$aid=DB::insert('forum_attachment',$attach,true);
if($attachment_score==0){
$attachment_info=array(
'aid' => $aid,
'uid' => $uid, //发布者id
'tid' => $tid,
'pid' => $pid,
'dateline' => time(),
'filename' => $file, //文件名称
'filesize' => filesize($new_file_path),
'attachment' => $attachment ,
);
}else{
$attachment_info=array(
'aid' => $aid,
'uid' => $uid, //发布者id
'tid' => $tid,
'pid' => $pid,
'dateline' => time(),
'filename' => $file, //文件名称
'filesize' => filesize($new_file_path),
'attachment' => $attachment ,
'price' => $attachment_score ,//附件积分
);
}
DB::insert('forum_attachment_'.$tableid,$attachment_info,true);
return $aid;
}
}
批量发帖
实现模拟批量上传附件之后,再来模拟批量发帖。代码参考discuz 内核实现。
$discuz_uid = 1; // uid
$discuz_user = 'admin'; //用户名
$fid = intval($_POST['fid']); //版块id
$typeid = 0;
$subject = substr(strrchr($dirs, '\\'),1); // 帖子标题
$message = $text_content.$word_content.$imgpng_content.$imgjpg_content; //
$timestamp = $_G['timestamp'];
$onlineip = $_G['clientip'];
$ismobile = 4; //
if($arr_attachment_file==NULL){
$newthread = array(
'fid' => $fid,
'posttableid' => 0,
'typeid' => $typeid,
'readperm' => '0',
'price' => '0',
'author' => $discuz_user,
'authorid' => $discuz_uid,
'subject' => $subject,
'dateline' => $timestamp,
'lastpost' => $timestamp,
'lastposter' => $discuz_user
);
$tid = C::t('forum_thread')->insert($newthread, true);
$subject = addslashes($subject);
$message = addslashes($message);
$pid = insertpost(array(
'fid' => $fid,
'tid' => $tid,
'first' => '1',
'author' => $discuz_user,
'authorid' => $discuz_uid,
'subject' => $subject,
'dateline' => $timestamp,
'message' => $message,
'useip' => $_G['clientip']
));
}else{
$newthread = array(
'fid' => $fid,
'posttableid' => 0,
'typeid' => $typeid,
'readperm' => '0',
'price' => '0',
'author' => $discuz_user,
'authorid' => $discuz_uid,
'subject' => $subject,
'dateline' => $timestamp,
'lastpost' => $timestamp,
'attachment'=>'1',
'lastposter' => $discuz_user
);
$tid = C::t('forum_thread')->insert($newthread, true);
$subject = addslashes($subject);
$message = addslashes($message);
$pid = insertpost(array(
'fid' => $fid,
'tid' => $tid,
'first' => '1',
'author' => $discuz_user,
'authorid' => $discuz_uid,
'subject' => $subject,
'dateline' => $timestamp,
'message' => $message,
'attachment'=>'1',
'useip' => $_G['clientip']
));
foreach($arr_attachment_file as $keyes=> $values ){
foreach($values as $file){
//批量添加附件
add_attachment($file,$tid,$pid,$dirs,$attachment_score);
}
}
}
DB::query("UPDATE pre_forum_forum SET lastpost='$timestamp', threads=threads+1, posts=posts+1, todayposts=todayposts+1 WHERE fid='$fid'", 'UNBUFFERED');
DB::query("UPDATE pre_common_member_count SET threads=threads+1 WHERE uid='$discuz_uid'", 'UNBUFFERED');
DB::query("UPDATE pre_common_member_status SET lastpost='$timestamp' WHERE uid='$discuz_uid'", 'UNBUFFERED');

本文标签:

很赞哦! ()

相关源码

  • 响应式帝国cms7.5NBA黑色体育资讯模板下载本模板为体育新闻媒体、报道机构设计,采用帝国CMS7.5内核开发,具备完整的资讯发布、体育日历、数据展示功能。响应式布局确保在手机端呈现实时资讯和图文内容查看源码
  • 自适应黑色简繁双语轴承齿轮机械设备制造网站模板该模板为轴承齿轮机械制造企业提供一体化网站建设方案,着重解决行业特有的多语言展示、移动端适配和高效率内容管理需求,帮助企业精准展示产品特性与工艺流程查看源码
  • (PC+WAP)激光水幕音乐喷泉设备工程网站源码下载本模板基于PbootCMS系统开发,为喷泉设备工程类企业设计,特别适合展示音乐喷泉、激光水幕等水景艺术项目。采用响应式技术,确保各类工程案例在不同设备上都能呈现视觉效果。查看源码
  • (自适应响应式)环保水净化处理设备阀门等网站源码下载基于PbootCMS内核开发的响应式模板,为水处理设备、空气净化器等环保企业设计,自适应手机端浏览。通过简洁高效的后台管理系统,助力环保科技企业快速建立专业在线展示平台。查看源码
  • 响应式艺考培训学校机构pbootcms模板html5源码基于PbootCMS免费开源内核开发,为艺考培训学校与艺术机构设计,替换图文即可快速适配全行业需求。响应式布局兼容手机/PC端,数据实时同步,运维效率提升300%。查看源码
  • (自适应)家禽饲养养殖基地pbootcms模板响应式模板下载为家禽饲养企业、养殖基地设计的响应式网站模板,聚焦畜禽产品展示、养殖技术分享及企业信息服务。采用PbootCMS内核开发,响应式技术确保PC与手机端数据实时同步查看源码
分享笔记 (共有 篇笔记)
验证码:

本栏推荐