Ejemplo n.º 1
0
 /**
  * 插入文章内容
  */
 public function writeArticle($ID, $Title, $Author, $DeptID, $Column, $TopAtDept, $TopAtAll, $WriteTime, $PublishTime, $Article, $FakeClick, $OriginalWriterID)
 {
     if (!empty($ID) && !empty($OriginalWriterID)) {
         $WriterID = $OriginalWriterID;
     } else {
         $WriterID = $_SESSION['user']['UserID'];
     }
     if ($_SESSION['user']['Type'] != 3) {
         if (!empty($ID) && $WriterID != $_SESSION['user']['UserID']) {
             $Published = 2;
         } else {
             $Published = 1;
         }
         //通过状态
         $CheckerID = $_SESSION['user']['UserID'];
     } else {
         $Published = 0;
         $CheckerID = 0;
         //ID0不存在,代表未审核
     }
     $imgurlCheck = new Application_Model_Admin_Admin();
     $imgurl = $imgurlCheck->GetImageSrc($Article);
     $imgurl = implode(",", $imgurl);
     $arr = array('Title' => $Title, 'ColumnID' => $Column, 'DeptID' => $DeptID, 'Article' => $Article, 'ImgUrl' => $imgurl, 'Author' => $Author, 'WriterID' => $WriterID, 'CheckerID' => $CheckerID, 'WriteTime' => $WriteTime, 'PublishTime' => $PublishTime, 'Published' => $Published, 'FakeClick' => $FakeClick, 'TopAtDept' => $TopAtDept, 'TopAtAll' => $TopAtAll);
     if (!empty($ID)) {
         $ab = $this->db->getAdapter();
         $where = $ab->quoteInto('ID=?', $ID);
         $res = $this->db->update($set = $arr, $where);
     } else {
         $res = $this->db->insert($arr);
     }
     // $this->checkTopArticleNum($type);
     return $res;
 }
Ejemplo n.º 2
0
 public function imageuploadAction()
 {
     $ArticleMapper = new Application_Model_ImageinfoMapper();
     $method = $this->_request->getParam("method");
     if ($method == "post") {
         $deptid = $this->_request->getParam("deptid");
         //实例化文件上传类
         $upload = new Zend_File_Transfer();
         $upload->addValidator('Size', false, 5 * 1024 * 1024);
         $upload->addValidator('Extension', false, 'jpg,gif,png');
         if (!$upload->isValid()) {
             echo "<script>alert('格式不符或文件过大,请重新尝试');location.href = '/admin/imageupload';</script>";
             exit;
         }
         //获取上传的文件表单,可以有多项
         $fileInfo = $upload->getFileInfo();
         $parseImg = new Application_Model_Admin_Admin();
         $filetmp = $parseImg->resize_image($fileInfo['imageFile']['name'], $fileInfo['imageFile']['tmp_name'], '480', '280');
         imagedestroy($fileInfo['imageFile']['tmp_name']);
         //获取后缀名,这里imageFile为上传表单file控件的name
         $ext = explode(".", $fileInfo['imageFile']['name']);
         $ext = $ext[1];
         //定义生成目录
         $dir = './upload' . date('/Y/m/');
         //文件重新命名
         do {
             $filename = date('His') . rand(100000, 999999) . '.' . $ext;
         } while (file_exists($dir . $filename));
         //如果目录不存在则创建目录
         if (!file_exists($dir)) {
             mkdir($dir, 0777, true);
         }
         //将图片正式写入
         $pass = imagejpeg($filetmp, $dir . '/' . $filename, 100);
         if (!$pass) {
             imagedestroy($filetmp);
             echo "<script>alert('图片资源上传失败,请重新尝试');location.href = '/admin/imageupload';</script>";
             exit;
         }
         imagedestroy($filetmp);
         //将图片信息插入数据库
         $i = $ArticleMapper->uploadImageInfo($filename, $_SESSION['user']['RealName'], $deptid);
         if (!isset($i)) {
             echo "<script>alert('图片信息上传失败,请重新尝试');location.href = '/admin/imageupload';</script>";
             exit;
         }
         echo "<script>alert('上传成功!');location.href = '/admin/imageupload';</script>";
     } else {
         //加载列表
         $DeptMapper = new Application_Model_DepartmentMapper();
         $arr = $DeptMapper->findAllDept();
         $this->view->arrDept = $arr;
         $this->view->imageArr = $ArticleMapper->selectImageInfo($_SESSION['user']['RealName']);
     }
 }