Example #1
0
 static function init()
 {
     if (!mysql_connect(Config::$db_host, Config::$db_user, Config::$db_pass)) {
         Response::out('db error ' . mysql_error());
     } else {
         mysql_select_db(Config::$db_name);
     }
 }
 /**
  * 上传图片处理方法,
  * 还有中文bug
  */
 public function upload($fileDir, $imgpath)
 {
     $adapter = new Zend_File_Transfer_Adapter_Http();
     // 不需要渲染模板页
     $this->getFrontController()->setParam('noViewRenderer', true);
     // 你存放上传文件的文件夹
     $adapter->setDestination($fileDir);
     $adapter->addValidator('Extension', false, 'gif,jpeg,png,jpg');
     //设置上传文件的后缀名
     $adapter->addValidator('Count', false, array('min' => 1, 'max' => 5));
     //设置上传文件的个数
     $adapter->addValidator('ImageSize', false, array('minwidth' => 0, 'maxwidth' => 40960, 'minhight' => 0, 'maxhight' => 40960));
     ////设置上传图片的大小
     $adapter->addValidator('FilesSize', false, array('min' => '4KB', 'max' => '4096KB'));
     ////设置上传文件的大小
     //添加过滤器来修改上传文件的名称
     if ($imgpath) {
         $adapter->addFilter('Rename', array('target' => $imgpath, 'overwrite' => true));
     }
     /* $fileInfo = $this->adapter->getFileInfo();
        foreach ($fileInfo as $file=>$info) {   //file-文件名
            if ($this->adapter->isValid($file)) {
                var_dump($info);die;
            }
        } */
     // 返回上传后出现在信息
     if (!$adapter->receive()) {
         /* $messages = $adapter->getMessages ();
            echo implode ( "n", $messages ); */
         $out[Response::ERRNO] = 0;
         $out[Response::MSG] = '上传成功!';
         Response::out($out);
         exit;
     } else {
         $out[Response::ERRNO] = 1;
         $out[Response::MSG] = '上传失败!';
         Response::out($out);
         exit;
     }
 }
 /**
  * 意见反馈接口
  * 测试url:http://139.196.198.121/usercenter/feedback?urid=7&feedback=gaga&app_id=1
  * return: errno:0-反馈成功;1-反馈失败;255-其他错误
  */
 public function feedbackAction()
 {
     $param = array(self::V_PARAM => '', self::URID_PARAM => '', self::FEEDBACK_PARAM => '', self::OS_PARAM => '');
     //接收参数
     Util::getParam($param);
     $urid = Arr::get($param, self::URID_PARAM);
     $feedback = Arr::get($param, self::FEEDBACK_PARAM);
     $os = Arr::get($param, self::OS_PARAM);
     if (!$urid || !$feedback || !$os) {
         $out['errno'] = 255;
         $out['msg'] = '参数错误';
         Response::out($out);
         exit;
     }
     $fbid = $this->_feedback->userFeedback($urid, $feedback, $os);
     if ($fbid) {
         //反馈成功
         $out['errno'] = 0;
         $out['msg'] = '反馈成功';
         Response::out($out);
         exit;
     } else {
         $out['errno'] = 1;
         $out['msg'] = '反馈失败';
         Response::out($out);
         exit;
     }
     exit;
 }
 /**
  * 讨论图片
  */
 public function discussimgAction()
 {
     // 这种方式能得到urid
     $imgpath = $_GET['imagename'];
     $fileDir = __PUBLIC__ . '/upload/image/discuss/';
     // $this->upload($fileDir, $imgpath);
     $adapter = new Zend_File_Transfer_Adapter_Http();
     // 不需要渲染模板页
     $this->getFrontController()->setParam('noViewRenderer', true);
     // 你存放上传文件的文件夹
     $adapter->setDestination($fileDir);
     $adapter->addValidator('Extension', false, 'gif,jpeg,png,jpg');
     // 设置上传文件的后缀名
     $adapter->addValidator('Count', false, array('min' => 1, 'max' => 5));
     // 设置上传文件的个数
     $adapter->addValidator('ImageSize', false, array('minwidth' => 0, 'maxwidth' => 40960, 'minhight' => 0, 'maxhight' => 40960));
     // //设置上传图片的大小
     $adapter->addValidator('FilesSize', false, array('min' => '4KB', 'max' => '4096KB'));
     // //设置上传文件的大小
     // 添加过滤器来修改上传文件的名称
     if ($imgpath) {
         $adapter->addFilter('Rename', array('target' => $imgpath, 'overwrite' => true));
     }
     // 返回上传后出现在信息
     if (!$adapter->receive()) {
         $out[Response::ERRNO] = 0;
         $out[Response::MSG] = '上传成功!';
         Response::out($out);
         exit;
     } else {
         $out[Response::ERRNO] = 1;
         $out[Response::MSG] = '上传失败!';
         Response::out($out);
         exit;
     }
 }
 /**
  * 评论
  * eg:http://139.196.198.121/longdistance/comment?ldid=3&urid=7&comment=gaga
  * eg:http://josanserver.com/longdistance/comment?ldid=3&urid=7&comment=gaga
  */
 public function commentAction()
 {
     $param = array(self::LDID_PARAM => '', self::URID_PARAM => '', self::COMMENT_PARAM => '');
     // 接收参数
     Util::getParam($param);
     $ldid = Arr::get($param, self::LDID_PARAM);
     $urid = Arr::get($param, self::URID_PARAM);
     $comment = Arr::get($param, self::COMMENT_PARAM);
     if (!$ldid || !$urid || !$comment) {
         $out['errno'] = 255;
         $out['msg'] = '参数错误';
         Response::out($out);
         exit;
     }
     $cmtid = $this->_comment->userComment($ldid, $urid, $comment);
     if ($cmtid) {
         // 评论成功
         $updateCommentNumResult = $this->_longdistance->updateCommentNum($ldid);
         if ($updateCommentNumResult) {
             $out['errno'] = 0;
             $out['msg'] = '评论成功';
             Response::out($out);
             exit;
         }
     } else {
         $out['errno'] = 1;
         $out['msg'] = '评论失败';
         Response::out($out);
         exit;
     }
     exit;
 }