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');
演示
茫茫多的文件夹

帖子列表
![auto_thread.png]
批量上传附件之后的帖子
![auto-post-2.png]
discuz 模拟批量上传附件发帖的更多相关文章
- Discuz模拟批量上传附件发帖
简介 对于很多用discuz做资源下载站来说,一个个上传附件,发帖是很繁琐的过程.如果需要批量上传附件发帖,就需要去模拟discuz 上传附件的流程. 模拟上传 discuz 附件逻辑 dz附件储存在 ...
- Discuz! X论坛上传附件到100%自动取消上传的原因及解决方案
最近接到一些站长的反馈,说论坛上传附件,到100%的时候自己取消上传了.经查是附件索引表pre_forum_attachment表的aid字段自增值出现了问题,导致程序逻辑返回的aid值实际为一个My ...
- formData批量上传的多种实现
前言 最近项目需要批量上传附件,查了下资料,网上很多但看着一脸懵,只贴部分代码,介绍也不详细,这里记录一下自己的采坑与多种实现,以免以后忘记. 这里先介绍下FormData对象,以下内容摘自:http ...
- 百度编辑器ueditor批量上传图片或者批量上传文件时,文件名称和内容不符合,错位问题
百度编辑器ueditor批量上传附件时,上传后的文件和实际文件名称错误,比如实际是文件名“dongcoder.xls”,上传后可能就成了“懂客.xls”.原因就是,上传文件时是异步上传,同时进行,导致 ...
- 文件批量上传-统一附件管理器-在线预览文件(有互联网和没有两种)--SNF快速开发平台3.0
实际上在SNF里使用附件管理是非常简单的事情,一句代码就可以搞定.但我也要在这里记录一下统一附件管理器能满足的需求. 通用的附件管理,不要重复开发,调用尽量简洁. 批量文件上传,并对每个文件大小限制, ...
- java上传附件,批量下载附件(一)
上传附件代码:借助commons-fileupload-1.2.jar package com.str; import java.io.BufferedInputStream;import java. ...
- 使用jQuery Uploadify在ASP.NET 上传附件
Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.Uploadify官方网址:http://www.uploadify.com/,在MVC中使用的方法可以参考 jQuer ...
- VB.NET上传附件代码
'附件添加 按钮 点击事件 吴翰哲 2013年7月23日 16:53:19 Protected Sub BtnAddFile_Click(ByVal sender As Object, ByVal e ...
- ux.plup.File plupload 集成 ux.plup.FileLis 批量上传预览
//plupload 集成 Ext.define('ux.plup.File', { extend: 'Ext.form.field.Text', xtype: 'plupFile', alias: ...
随机推荐
- Count the Colors(线段树染色)
Count the Colors Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit ...
- Redis集群创建报错
Redis集群环境:och163/och164/och165 在执行如下脚本时报错: ./src/redis-trib.rb create 10.1.253.163: 10.1.253.164: 10 ...
- Open XML SDK 在线编程黑客松
2015年2月10日-3月20日,开源社 成员 微软开放技术,GitCafe,极客学院联合举办" Open XML SDK 在线编程黑客松 ",为专注于开发提高生产力的应用及服务的 ...
- python-appium练习编写脚本时遇到问题
遇到问题: 1.安卓4.2及以下系统无法识别resource-id属性 只能用text属性识别 2.输入中文无法识别 脚本最顶部增加#coding=utf-8 3.对象无法识别resource-id属 ...
- java.lang.NumberFormatException: For input string: "Y"
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. ...
- Oracle对表解锁的操作
1.查出被锁的表 SELECT lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username User_name, o.owner,o.object_na ...
- mongodb 文件,图片存储数据库
mongodb 文件,图片存储数据库
- [SSH 3]以网上商城项目浅谈spring配置
导读:在做ITOO项目的时候,就用到了容器+反射,从而运用了依赖注入和依赖查找.如果看过WCF端的配置文件,那么对于这个spring的配置就很容易理解.本篇博客,是对于自己做的一个小项目中所运用到的s ...
- js的数组申明
//数组的3种申明方法,如下example //数组是一种object类型 通过typeof 来检查 //example 1 var arr= new Array("h",&quo ...
- 【MySQL】MySQL/MariaDB的优化器对in子查询的处理
参考:http://codingstandards.iteye.com/blog/1344833 上面参考文章中<高性能MySQL>第四章第四节在第三版中我对应章节是第六章第五节 最近分析 ...