免费分享phpwind8.5 发布主要逻辑 - 支持图片上传
看了一下火车官方的发布接口,其实不咋样,好多功能都没弄上去的。然后我自己想到了一个比较好的方法来做接口。就是修改mysqli.class.php文件,在执行sql的地方加入记录操作如:
$hd = fopen('log.txt', 'a');
fwrite($hd, $sql);
这样就可以把发帖子过程的sql全部记录下来,这样基本省去了看程序的时间,直接把收集的sql来做接口。
下面给出的代码只指明了思路,因为是从我的一个类里抽出的逻辑,没有其他环境不能运行。
另外图片上传部分也没有在里面,只包含了图片数据的插入。function insertArticle($title, $content){
$this->db = Database::getInstance();
$db_address = "localhost";
$db_username = "root";
$db_password = "111111";
$db_database = "phpwind";
$this->db = Database::getInstance();
$this->db->execConnect($db_address, $db_username, $db_password, $db_database, 0, 'utf8', 'phpwind');
$hasImage = is_array($this->arrImage) && count($this->arrImage) ? 1 : 0;
// create a new thread
$sql = "INSERT INTO`pw_threads` SET `fid`='" . $this->forumid . "',`icon`='0',";
$sql .= "`author`='" . $this->author . "' ,`authorid`='" . $this->userid . "' ,";
$sql .= "`subject`='" . $title . "' ,`ifcheck`='1' ,`type`='0' ,`postdate`='" . time() . "' ,";
$sql .= "`lastpost`='" . time() . "' ,`lastposter`='" . $this->author . "' ,`hits`='1' ,";
$sql .= "`replies`='0' ,`topped`='0' ,`digest`='0' ,`special`='0' ,`state`='0',";
$sql .= "`ifupload`='" . $hasImage . "' ,`ifmail`='0' ,`anonymous`='0' ,`ptable`='' ,";
$sql .= "`ifmagic`='0' ,`ifhide`='0' ,`tpcstatus`='0' ,`modelid`='0' ";
$this->db->query($sql);
$tid = $this->db->getInsertId();
// insert the content
$sql = "INSERT INTO pw_tmsgs SET `tid` ='" . $tid . "',`aid` ='" . $this->userid . "',`userip` ='68.190.228.135',";
$sql .= "`ifsign` ='1',`buy` ='',`ipfrom` ='北京',`tags` ='',`ifconvert` ='1',`ifwordsfb` ='1',";
$sql .= "`content` ='" . mysql_real_escape_string($content) . "', `magic` =''";
$this->db->query($sql);
if(is_array($this->arrImage) && count($this->arrImage)){
foreach($this->arrImage as $arrOneImage){
$sql = "INSERT INTO pw_attachs SET `fid` ='" . $this->forumid . "',`uid` ='" . $this->userid . "',";
$sql .= "`tid` ='" . $tid . "',`pid` ='0',`hits` ='0',`name` ='" . $arrOneImage['fakename'] . "',`type` ='img',";
$sql .= "`size` ='" . $arrOneImage['size'] . "',`attachurl` ='" . $arrOneImage['filename'] . "',";
$sql .= "`uploadtime` ='" . time() . "',`ifthumb` ='2'";
$this->db->query($sql);
}
}
$sql = "UPDATE pw_forumdata SET tpost=tpost+'1',article=article+'1',topic=topic+'1' ,lastpost='" . $title . " " . $this->author . " " . time() . " read.php?tid=" . $tid . "&page=e#a'WHERE fid= '" . $this->forumid . "'";
$this->db->query($sql);
} 刚好需要这个ali7ls 这个是论坛的部分 {:1_203:}感谢,只要知道储存方式,就能写出来了
页:
[1]