$result['error'] = 0;
     $result['message'] = "访问微信接口错误, 错误代码: {$content['errcode']}, 错误信息: {$content['errmsg']},错误详情:{$acc->error_code($content['errcode'])}";
     die(json_encode($result));
 }
 if ($mode == 'perm' || $mode == 'temp') {
     if (!empty($content['media_id'])) {
         $result['media_id'] = $content['media_id'];
     }
     if (!empty($content['thumb_media_id'])) {
         $result['media_id'] = $content['thumb_media_id'];
     }
 } elseif ($mode == 'file_upload') {
     $result['media_id'] = $content['url'];
 }
 if ($type == 'image' || $type == 'thumb') {
     $file['path'] = file_image_thumb($fullname, '', 300);
 }
 $insert = array('uniacid' => $_W['uniacid'], 'acid' => $acid, 'uid' => $_W['uid'], 'filename' => $originname, 'attachment' => $file['path'], 'media_id' => $result['media_id'], 'type' => $type, 'model' => $mode, 'createtime' => TIMESTAMP);
 if ($type == 'image' || $type == 'thumb') {
     $size = getimagesize($fullname);
     $insert['width'] = $size[0];
     $insert['height'] = $size[1];
 }
 if ($type == 'video') {
     $insert['tag'] = iserializer($description);
 }
 pdo_insert('core_wechats_attachment', $insert);
 $result['type'] = $type;
 $result['url'] = $_W['attachurl'] . $file['path'];
 if ($type == 'image' || $type == 'thumb') {
     @unlink($fullname);
Example #2
0
 }
 if ($thumb == 1 && $width > 0) {
     $extention = pathinfo($srcfile, PATHINFO_EXTENSION);
     do {
         if (!empty($option['global'])) {
             $filename = "{$_W['uploadsetting']['image']['folder']}/" . random(30) . ".{$extention}";
         } else {
             if (empty($dest_dir)) {
                 $filename = "{$_W['uploadsetting']['image']['folder']}/" . date('Y/m/') . random(30) . ".{$extention}";
             } else {
                 $filename = "{$_W['uploadsetting']['image']['folder']}/" . $dest_dir . '/' . random(30) . ".{$extention}";
             }
         }
     } while (file_exists(ATTACHMENT_ROOT . '/' . $result['path'] . $filename));
     $result['path'] .= $filename;
     $r = file_image_thumb($srcfile, $path . $result['path'], $option['width']);
     @unlink($srcfile);
     if (is_error($r)) {
         $result['message'] = $r['message'];
         frameCallback($_GPC['callback'], json_encode($result));
         exit;
     }
 } else {
     $result['path'] = $file['path'];
 }
 $result['filename'] = $result['path'];
 $result['url'] = $_W['attachurl'] . $result['path'];
 $result['error'] = 0;
 pdo_insert('core_attachment', array('uniacid' => $_W['uniacid'], 'uid' => $_W['uid'], 'filename' => $_FILES['file']['name'], 'attachment' => $result['filename'], 'type' => 1, 'createtime' => TIMESTAMP));
 frameCallback($_GPC['callback'], json_encode($result));
 exit;
Example #3
0
function uploadAvatarImage($upfile, $upload_path, $maxfilesize, $uptypes)
{
    $name = $upfile['name'];
    $type = $upfile['type'];
    $size = $upfile['size'];
    $tmp_name = $upfile['tmp_name'];
    $error = $upfile['error'];
    //上传路径
    if (intval($error) > 0) {
        exit('上传错误:错误代码:' . $error);
    } else {
        //上传文件大小0为不限制,默认2M
        if ($maxfilesize > 0) {
            if ($size > $maxfilesize * 1024 * 1024) {
                exit('上传文件过大' . $_FILES["file"]["error"]);
            }
        }
        //允许上传的图片类型
        //判断文件的类型
        if (!in_array($type, $uptypes)) {
            exit('上传文件类型不符:' . $type);
        }
        //存放目录
        if (!file_exists($upload_path)) {
            mkdir($upload_path);
        }
        //取文件后缀
        //$suffix = strrev( substr(strrev($name), 0, strpos(strrev($name), '.')));
        //移动文件
        $source_filename = $person_id . '_' . date("Ymd");
        $target_filename = $person_id . '_' . date("Ymd") . '.thumb.jpg';
        if (!move_uploaded_file($tmp_name, $upload_path . $source_filename)) {
            exit('移动文件失败');
        }
        //营业执照进行缩略
        $srcfile = $upload_path . $source_filename;
        $desfile = $upload_path . $target_filename;
        //文件操作类
        load()->func('file');
        $ret = file_image_thumb($srcfile, $desfile, 320);
        //$ret = file_image_crop($srcfile, $desfile, 400, 400 ,5);//裁剪
        if (!is_array($ret)) {
            //路径存入数据库
            $person_data['headimgurl'] = $target_filename;
        }
        //删除原图
        unlink($srcfile);
    }
}
Example #4
0
 /**
  * @param $upload_name
  * @param string $asname
  * @param bool $thumb
  * @param int $width
  * @param int $height
  * @param int $position
  * @return string
  */
 public function upload_img($upload_name, $asname = '', $thumb = true, $width = 320, $height = 240, $position = 5)
 {
     //文件操作类
     load()->func('file');
     $upfile = $_FILES[$upload_name];
     $name = $upfile['name'];
     $type = $upfile['type'];
     $size = $upfile['size'];
     $tmp_name = $upfile['tmp_name'];
     $error = $upfile['error'];
     //上传路径
     $upload_path = IA_ROOT . "/attachment/thinkidea_rencai/";
     load()->func('file');
     @mkdirs($upload_path);
     if (intval($error) > 0) {
         message('上传错误:错误代码:' . $upload_name . '-' . $error, 'referer', 'error');
     } else {
         //上传文件大小0为不限制,默认2M
         $maxfilesize = empty($this->module['config']['maxfilesize']) ? 2 : intval($this->module['config']['maxfilesize']);
         if ($maxfilesize > 0) {
             if ($size > $maxfilesize * 1024 * 1024) {
                 message('上传文件过大' . $_FILES["file"]["error"], 'referer', 'error');
             }
         }
         //允许上传的图片类型
         $uptypes = array('image/jpg', 'image/png', 'image/jpeg');
         //判断文件的类型
         if (!in_array($type, $uptypes)) {
             message('上传文件类型不符:' . $type, 'referer', 'error');
         }
         //存放目录
         if (!file_exists($upload_path)) {
             mkdir($upload_path);
         }
         //移动文件
         if (!move_uploaded_file($tmp_name, $upload_path . date("YmdHi") . '_' . $name)) {
             message('移动文件失败,请检查服务器权限', 'referer', 'error');
         }
         $srcfile = $upload_path . date("YmdHi") . '_' . $name;
         $desfile = $upload_path . date("YmdHi") . '_' . $name . '.' . $asname . '.thumb.jpg';
         if ($thumb) {
             file_image_thumb($srcfile, $desfile, $width);
         } else {
             file_image_crop($srcfile, $desfile, $width, $height, 5);
         }
         return date("YmdHi") . '_' . $name . '.' . $asname . '.thumb.jpg';
     }
 }
Example #5
0
 public function doMobileUploadImage3()
 {
     global $_W, $_GPC;
     $openid = $_W['openid'];
     $weid = $_W['weid'];
     $cfgs = $this->module['config'];
     $result = array();
     if (empty($openid) || empty($_POST['id']) || empty($_GPC['geter'])) {
         $back = array('succ' => '0', 'message' => '参数错误');
     } else {
         $sql = "SELECT id FROM " . tablename('hnblacklist') . " WHERE wantblack = :wantblack AND blackwho = :blackwho AND weid=:weid";
         $paras = array(':wantblack' => $openid, ':blackwho' => $_GPC['geter'], ':weid' => $weid);
         $result = pdo_fetchcolumn($sql, $paras);
         if (!empty($result)) {
             $back = array('succ' => '0', 'message' => '你已将对方拉入黑名单');
         } else {
             $sql2 = "SELECT id FROM " . tablename('hnblacklist') . " WHERE wantblack = :wantblack AND blackwho = :blackwho AND weid=:weid";
             $paras2 = array(':wantblack' => $_GPC['geter'], ':blackwho' => $openid, ':weid' => $weid);
             $uresult = pdo_fetchcolumn($sql2, $paras2);
             if (!empty($uresult)) {
                 $back = array('succ' => '0', 'message' => '对方已将你拉入黑名单');
             } else {
                 $baoyue = pdo_fetchcolumn("SELECT endtime FROM " . tablename('meepohn_baoyue') . " WHERE openid=:openid AND weid=:weid ORDER BY endtime DESC", array(':weid' => $weid, ':openid' => $_GPC['sender']));
                 if (empty($baoyue) || TIMESTAMP > $baoyue) {
                     //未开通包月或者包月过期
                     $payment = !empty($cfgs['chatpay']) ? intval($cfgs['chatpay']) : 0;
                     load()->model('mc');
                     $member = mc_fetch($_W['member']['uid']);
                     if ($member['credit1'] >= $payment) {
                         load()->func('communication');
                         load()->classs('weixin.account');
                         $accObj = WeixinAccount::create($_W['account']['acid']);
                         $access_token = $accObj->fetch_token();
                         $token2 = $access_token;
                         $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $token2 . '&media_id=' . $_POST['id'];
                         $pic_data = ihttp_request($url);
                         $path = "images/meepoxiangqin/";
                         $path2 = "images/meepoxiangqinthumb/";
                         load()->func('file');
                         $picurl = $path . random(30) . ".jpg";
                         $thumbimg = $path2 . random(30) . ".jpg";
                         file_write($picurl, $pic_data['content']);
                         $thumb = file_image_thumb(IA_ROOT . '/attachment/' . $picurl, IA_ROOT . '/attachment/' . $thumbimg, $width = 70);
                         if (!is_array($thumb)) {
                             $thumburl = $thumb;
                         } else {
                             $thumburl = $picurl;
                         }
                         $sender = $_W['fans']['from_user'];
                         $senderuid = pdo_fetch("SELECT * FROM " . tablename('hnfans') . " WHERE from_user = '******' AND weid = '{$weid}'");
                         $senderavatar = $senderuid['avatar'];
                         $sendernickname = $senderuid['nickname'];
                         $data = array('sender' => $sender, 'geter' => $_GPC['geter'], 'content' => $picurl, 'msgtype' => 'images', 'thumburl' => $thumburl, 'stime' => time(), 'weid' => $weid, 'sendernickname' => $sendernickname);
                         if (preg_match('/http:(.*)/', $senderavatar)) {
                             $data['senderavatar'] = $senderavatar;
                         } elseif (preg_match('/images(.*)/', $senderavatar)) {
                             $data['senderavatar'] = $_W['attachurl'] . $senderavatar;
                         } else {
                             $data['senderavatar'] = MEEPORES . "/static/friend/images/cdhn80.jpg";
                         }
                         $res = pdo_insert('hnmessage', $data);
                         pdo_update("hnfans", array("mails" => $senderuid['mails'] + 1), array("from_user" => $_GPC['geter'], "weid" => $weid));
                         $btime = date('Y-m-d' . '00:00:00', time());
                         $btimestr = strtotime($btime);
                         $max = pdo_fetchcolumn("SELECT count(*) FROM " . tablename('hnmessage') . " WHERE sender=:sender AND geter=:geter  AND weid=:weid AND stime>:stime", array(':sender' => $sender, ':geter' => $_GPC['geter'], ':weid' => $weid, ':stime' => $btimestr));
                         $cfgnum = intval($cfgs['maxnum']);
                         if ($cfgnum) {
                             if ($max < $cfgnum) {
                                 $this->sendmessage($_GPC['content'], $_GPC['geter']);
                             }
                         } else {
                             $this->sendmessage($_GPC['content'], $_GPC['geter']);
                         }
                         $back['succ'] = '1';
                         $back['picurl'] = $picurl;
                         $back['thumburl'] = $thumburl;
                         $touid = $_W['member']['uid'];
                         pdo_query("UPDATE " . tablename('mc_members') . " SET credit1 = credit1 - '{$payment}' WHERE uid = '{$touid}' AND uniacid='{$weid}' ");
                     } else {
                         $back = array('succ' => '2', 'message' => '积分余额不足');
                     }
                 } else {
                     load()->func('communication');
                     load()->classs('weixin.account');
                     $accObj = WeixinAccount::create($_W['account']['acid']);
                     $access_token = $accObj->fetch_token();
                     $token2 = $access_token;
                     $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $token2 . '&media_id=' . $_POST['id'];
                     $pic_data = ihttp_request($url);
                     $path = "images/meepoxiangqin/";
                     $path2 = "images/meepoxiangqinthumb/";
                     load()->func('file');
                     $picurl = $path . random(30) . ".jpg";
                     $thumbimg = $path2 . random(30) . ".jpg";
                     file_write($picurl, $pic_data['content']);
                     $thumb = file_image_thumb(IA_ROOT . '/attachment/' . $picurl, IA_ROOT . '/attachment/' . $thumbimg, $width = 70);
                     if (!is_array($thumb)) {
                         $thumburl = $thumb;
                     } else {
                         $thumburl = $picurl;
                     }
                     $sender = $_W['fans']['from_user'];
                     $senderuid = pdo_fetch("SELECT * FROM " . tablename('hnfans') . " WHERE from_user = '******' AND weid = '{$weid}'");
                     $senderavatar = $senderuid['avatar'];
                     $sendernickname = $senderuid['nickname'];
                     $data = array('sender' => $sender, 'geter' => $_GPC['geter'], 'content' => $picurl, 'msgtype' => 'images', 'thumburl' => $thumburl, 'stime' => time(), 'weid' => $weid, 'sendernickname' => $sendernickname);
                     if (preg_match('/http:(.*)/', $senderavatar)) {
                         $data['senderavatar'] = $senderavatar;
                     } elseif (preg_match('/images(.*)/', $senderavatar)) {
                         $data['senderavatar'] = $_W['attachurl'] . $senderavatar;
                     } else {
                         $data['senderavatar'] = MEEPORES . "/static/friend/images/cdhn80.jpg";
                     }
                     $res = pdo_insert('hnmessage', $data);
                     pdo_update("hnfans", array("mails" => $senderuid['mails'] + 1), array("from_user" => $_GPC['geter'], "weid" => $weid));
                     $btime = date('Y-m-d' . '00:00:00', time());
                     $btimestr = strtotime($btime);
                     $max = pdo_fetchcolumn("SELECT count(*) FROM " . tablename('hnmessage') . " WHERE sender=:sender AND geter=:geter  AND weid=:weid AND stime>:stime", array(':sender' => $sender, ':geter' => $_GPC['geter'], ':weid' => $weid, ':stime' => $btimestr));
                     $cfgnum = intval($cfgs['maxnum']);
                     if ($cfgnum) {
                         if ($max < $cfgnum) {
                             $this->sendmessage($_GPC['content'], $_GPC['geter']);
                         }
                     } else {
                         $this->sendmessage($_GPC['content'], $_GPC['geter']);
                     }
                     $back['succ'] = '1';
                     $back['picurl'] = $picurl;
                     $back['thumburl'] = $thumburl;
                 }
             }
         }
     }
     die(json_encode($back));
 }
Example #6
0
     $result['error']['message'] = '上传失败,请重试!';
     die(json_encode($result));
 }
 $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
 $ext = strtolower($ext);
 $file = file_upload($_FILES['file']);
 if (is_error($file)) {
     $result['error']['message'] = $file['message'];
     die(json_encode($result));
 }
 $pathname = $file['path'];
 $fullname = ATTACHMENT_ROOT . '/' . $pathname;
 $thumb = empty($setting['thumb']) ? 0 : 1;
 $width = intval($setting['width']);
 if ($thumb == 1 && $width > 0) {
     $thumbnail = file_image_thumb($fullname, '', $width);
     @unlink($fullname);
     if (is_error($thumbnail)) {
         $result['message'] = $thumbnail['message'];
         die(json_encode($result));
     } else {
         $filename = pathinfo($thumbnail, PATHINFO_BASENAME);
         $pathname = $thumbnail;
         $fullname = ATTACHMENT_ROOT . '/' . $pathname;
     }
 }
 $info = array('name' => $_FILES['file']['name'], 'ext' => $ext, 'filename' => $pathname, 'attachment' => $pathname, 'url' => tomedia($pathname), 'is_image' => 1, 'filesize' => filesize($fullname));
 $size = getimagesize($fullname);
 $info['width'] = $size[0];
 $info['height'] = $size[1];
 setting_load('remote');
Example #7
0
 public function doMobileUploadImage3()
 {
     global $_W, $_GPC;
     $openid = $_W['openid'];
     $weid = $_W['weid'];
     $result = array();
     if (empty($openid) || empty($_POST['id']) || empty($_GPC['geter'])) {
         die('0');
     }
     load()->func('communication');
     load()->classs('weixin.account');
     $accObj = WeixinAccount::create($_W['account']['acid']);
     $access_token = $accObj->fetch_token();
     $token2 = $access_token;
     $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $token2 . '&media_id=' . $_POST['id'];
     $pic_data = ihttp_request($url);
     $path = "images/meepoxiangqin/";
     $path2 = "images/meepoxiangqinthumb/";
     load()->func('file');
     $picurl = $path . random(30) . ".jpg";
     $thumbimg = $path2 . random(30) . ".jpg";
     file_write($picurl, $pic_data['content']);
     $thumb = file_image_thumb(IA_ROOT . '/attachment/' . $picurl, IA_ROOT . '/attachment/' . $thumbimg, $width = 70);
     if (!is_array($thumb)) {
         $thumburl = $thumb;
     } else {
         $thumburl = $picurl;
     }
     $sender = $_W['fans']['from_user'];
     $senderuid = pdo_fetch("SELECT * FROM " . tablename('hnfans') . " WHERE from_user = '******' AND weid = '{$weid}'");
     $senderavatar = $senderuid['avatar'];
     $sendernickname = $senderuid['nickname'];
     $data = array('sender' => $sender, 'geter' => $_GPC['geter'], 'content' => $picurl, 'msgtype' => 'images', 'thumburl' => $thumburl, 'stime' => time(), 'weid' => $weid, 'sendernickname' => $sendernickname);
     if (preg_match('/http:(.*)/', $senderavatar)) {
         $data['senderavatar'] = $senderavatar;
     } elseif (preg_match('/images(.*)/', $senderavatar)) {
         $data['senderavatar'] = $_W['attachurl'] . $senderavatar;
     } else {
         $data['senderavatar'] = MEEPORES . "/static/friend/images/cdhn80.jpg";
     }
     $res = pdo_insert('hnmessage', $data);
     pdo_update('hnfans', array('mails' => $senderuid['mails'] + 1), array("from_user" => $_GPC['geter'], "weid" => $weid));
     if ($res) {
         $btime = date('Y-m-d' . '00:00:00', time());
         $btimestr = strtotime($btime);
         $sql = "SELECT * FROM " . tablename('hnmessage') . " WHERE sender=:sender AND geter=:geter AND mloop=:mloop AND weid=:weid AND stime>:stime";
         $checkit = pdo_fetchall($sql, array(':sender' => $_GPC['geter'], ':geter' => $sender, ':mloop' => 1, ':weid' => $weid, ':stime' => $btimestr));
         $cfgs = $this->module['config'];
         $cfgnum = intval($cfgs['maxnum']);
         if ($cfgnum) {
             if (count($checkit) < $cfgnum) {
                 $this->sendmessage($_GPC['content'], $_GPC['geter']);
             }
         } else {
             $this->sendmessage($_GPC['content'], $_GPC['geter']);
         }
         $back['picurl'] = $picurl;
         $back['thumburl'] = $thumburl;
         die(json_encode($back));
     } else {
         die('0');
     }
 }