diff --git a/application/default/controllers/HeiheController.php b/application/default/controllers/HeiheController.php index fa09bb4f..d2480b00 100644 --- a/application/default/controllers/HeiheController.php +++ b/application/default/controllers/HeiheController.php @@ -839,6 +839,11 @@ class HeiheController extends DataController if($ac == "upload") { + $this->_helper->layout->setLayout('layout-iframe'); + $this->_helper->viewRenderer('project-upload'); + + $submit = $this->_getParam('submit'); + $pid = $this->_getParam('pid'); if(empty($pid) || !is_numeric($pid)) @@ -847,6 +852,8 @@ class HeiheController extends DataController return true; } + $this->view->pid = $pid; + if(empty($uid)) { $this->view->error = "请先登录"; @@ -863,6 +870,60 @@ class HeiheController extends DataController return true; } + if(!empty($submit) && empty($this->view->error)) + { + + $files=new files(); + $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe'); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = $msg['file_type']; + $realname = $msg['realname']; + + if(!empty($row['attachid'])) + { + $sql = "SELECT * FROM attachments WHERE id={$row['attachid']}"; + $sth = $this->db->query($sql); + $attach = $sth->fetch(); + $this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'"); + @unlink($this->view->config->upload.$attach['filename']); + } + + $sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values + ('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + + $sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid"; + $sth = $this->db->exec($sql); + + if($sth) + { + $this->view->message = "上传成功"; + }else{ + @unlink($filename); + $this->view->error = '附件上传失败:写入附件表出错'; + return true; + } + }else{ + @unlink($filename); + $this->view->error = "附件上传失败".$msg['error']; + return true; + } + } + + $sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}"; + $sth = $this->db->query($sql); + $this->view->att = $sth->fetch(); + + return true; } if(!empty($invite)) diff --git a/application/default/views/scripts/heihe/project-upload.phtml b/application/default/views/scripts/heihe/project-upload.phtml new file mode 100644 index 00000000..7e954e10 --- /dev/null +++ b/application/default/views/scripts/heihe/project-upload.phtml @@ -0,0 +1,46 @@ +headTitle($this->config->title->site); + $this->headTitle('上传计划'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); + $this->breadcrumb()->setSeparator(' > '); + $this->headScript()->appendFile('/js/jquery-1.7.min.js'); + $this->headScript()->appendFile('/js/jquery.colorbox-min.js'); + $this->headLink()->appendStylesheet('/css/colorbox.css'); + $this->headLink()->appendStylesheet('/css/author.css'); + $this->headScript()->appendFile('/static/js/uploadify/swfobject.js'); + $this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js'); + $this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css'); +?> +error)) +{ + echo $this->error; + echo ""; +}else{?> + message)) + { + echo "

".$this->message."

"; + }?> + att)) + { + echo '
+
'; + } + ?> +
+
+

注:只能选择一个文件,如果重新上传,将自动替换之前上传的文件
+ + + +

+
+
+ +