Example #1
0
 /**
  * 检查上传头像信息
  * @param string $uploadformname 上传文件的表单名
  * @return boolean 不合格时返回false,错误信息见$message
  */
 public function check($uploadformname)
 {
     //获取上传的文件
     $upfile = isset($_FILES[$uploadformname]) ? $_FILES[$uploadformname] : null;
     if (empty($upfile)) {
         self::$message = '没有提交图像';
         return false;
     }
     if (!is_uploaded_file($upfile['tmp_name'])) {
         self::$message = '图片不存在';
         return false;
     }
     if ($upfile['error'] != 0) {
         self::$message = '上传文件出错(' . $upfile['error'] . ')';
         return false;
     }
     //图像类型
     $imgtype = filesize($upfile['tmp_name']) > 11 ? exif_imagetype($upfile['tmp_name']) : false;
     if (!$imgtype) {
         self::$message = '上传文件格式非图片';
         return false;
     }
     if (!in_array($imgtype, $this->_extension)) {
         self::$message = '上传的图片格式不允许';
         return false;
     }
     $size = getimagesize($upfile['tmp_name']);
     if (!empty($this->_width) && $size[0] > $this->_width) {
         self::$message = '图片宽度超出限制';
         return false;
     }
     if (!empty($this->_height) && $size[1] > $this->_height) {
         self::$message = '图片高度超出限制';
         return false;
     }
     if (!empty($this->_minsize) && $upfile['size'] < $this->_minsize) {
         self::$message = '图片文件太小';
         return false;
     }
     if ($upfile['size'] > $this->_maxsize) {
         self::$message = '图片文件太大';
         return false;
     }
     //处理存储文件名
     if (empty($this->_savename)) {
         $this->_savename = md5(uniqid(microtime(), true));
     }
     $typeArr = array_flip($this->_extension);
     //加上文件名后缀
     $this->_savename .= '.' . $typeArr[$imgtype];
     return true;
 }
Example #2
0
 public function mod()
 {
     $id = (int) $this->getUrlVar('id');
     $res = DBproxy::getProcedure('Manage')->setDimension(2)->getBook(array('id' => $id), '1');
     if (empty($res)) {
         $this->alert('data null');
     }
     if ($this->isAjax() && $_POST) {
         $v = Doo::loadHelper('DooValidator', true);
         $success = true;
         $errors = array();
         $rules = $this->_getFormRule();
         // 验证数据
         if ($errors = $v->validate($_POST, $rules)) {
             $success = false;
         }
         //数据处理
         if ($success) {
             //图片处理
             $img = '';
             Doo::loadClassAt('Picupload', 'default');
             $Picupload = new Picupload();
             $imgRes = $Picupload->upload('img');
             if ($imgRes) {
                 $img = $Picupload::$picinfo['dirname'] . '/' . $Picupload::$picinfo['basename'];
             } else {
                 $img = trim($_POST['img']);
             }
             //数据处理
             $param['categoryid'] = intval($_POST['categoryid']);
             $param['name'] = trim($_POST['name']);
             $param['sort'] = intval($_POST['sort']);
             $param['status'] = intval($_POST['status']);
             $param['la'] = trim($_POST['la']);
             $param['descript'] = trim($_POST['descript']);
             $param['img'] = $img;
             $param['price'] = trim($_POST['price']);
             $param['wxprice'] = trim($_POST['wxprice']);
             $param['peiSongSum'] = intval($_POST['peiSongSum']);
             $res = DBproxy::getProcedure('Manage')->setDimension(2)->bookIU('u', $param, $id);
             if ($res['status'] != 0) {
                 $success = false;
                 $errors[] = 'DB异常!';
             }
         }
         // 处理返回路径
         if ($success) {
             if (isset($_POST['saveAndReutrn'])) {
                 $errors = BookController::$dataTableUrl;
             } else {
                 $errors = BookController::$addUrl;
             }
         }
         // 处理表单位提交
         $this->ajaxFormResult($success, $errors);
     } else {
         // 显示生成表单
         Doo::loadClassAt('html/DooFormExt', 'default');
         $form = new DooFormExt($this->_getFormConfig(false, $res['data'][0]));
         $btn = '<a class="btn green-stripe" href="' . BookController::$dataTableUrl . '"><i class="icon-backward"> </i>' . L('列表') . '</a>';
         // 显示模版
         $this->contentlayoutRender($btn . $form->render());
     }
 }