Ejemplo n.º 1
0
 public function ajax_upload_pic()
 {
     if (isset($_FILES['pic']) && $_FILES['pic']['error'] == 0) {
         $ret = uploadOne('pic', 'Temp', array(array(650, 650, 2), array(130, 130, 2)));
         //将图片用js输出到页面iframe中
         // 构造一个图片的LI标签,并添加一个删除的按钮
         $img = "<li>";
         $img .= "<input onclick=\\'this.parentNode.parentNode.removeChild(this.parentNode);\\' type=\\'button\\' value=\\'删除\\' /><br />";
         // 放个删除图片的按钮
         $img .= "<img src=\\'/Public/Uploads/{$ret['images'][2]}\\' />";
         // 图片显示在页面中
         $img .= "<input name=\\'pic[]\\' type=\\'hidden\\' value=\\'{$ret['images'][0]}\\' />";
         // 原图路径放到页面中
         $img .= "<input name=\\'mid_pic[]\\' type=\\'hidden\\' value=\\'{$ret['images'][1]}\\' />";
         // 中图路径放到页面中
         $img .= "<input name=\\'sm_pic[]\\' type=\\'hidden\\' value=\\'{$ret['images'][2]}\\' />";
         // 小图路径放到页面中
         $img .= "</li>";
         // 把图片显示在页面中上
         $option = "<script>";
         $option .= "parent.document.getElementById('pic_container').innerHTML+='{$img}';";
         // 图片显示在页面上
         $option .= "parent.document.getElementById('loading').innerHTML='';";
         // 把加载的loading图片去掉
         $option .= "parent.document.getElementById('upload_form').reset();";
         // 重置图片表单
         $option .= "</script>";
         echo $option;
     }
 }
Ejemplo n.º 2
0
 protected function _before_update(&$data, $option)
 {
     if (isset($_FILES['brand_logo']) && $_FILES['brand_logo']['error'] == 0) {
         $ret = uploadOne('brand_logo', 'Admin', array());
         if ($ret['ok'] == 1) {
             $data['brand_logo'] = $ret['images'][0];
         } else {
             $this->error = $ret['error'];
             return FALSE;
         }
         deleteImage(array(I('post.old_brand_logo')));
     }
 }
Ejemplo n.º 3
0
 protected function _before_update(&$data, $option)
 {
     if (isset($_FILES['logo']) && $_FILES['logo']['error'] == 0) {
         $ret = uploadOne('logo', 'Admin', array(array(350, 350, 2), array(150, 150, 2), array(50, 50, 2)));
         if ($ret['ok'] == 1) {
             $data['logo'] = $ret['images'][0];
             $data['big_logo'] = $ret['images'][1];
             $data['mid_logo'] = $ret['images'][2];
             $data['sm_logo'] = $ret['images'][3];
         } else {
             $this->error = $ret['error'];
             return FALSE;
         }
         deleteImage(array(I('post.old_logo'), I('post.old_big_logo'), I('post.old_mid_logo'), I('post.old_sm_logo')));
     }
 }
Ejemplo n.º 4
0
 public function upload()
 {
     if (IS_POST) {
         $res = uploadOne(array('dir' => '', 'exts' => 'apk', 'save' => 'WeiLang'));
         if ($res['success']) {
             $result = array();
             $result['status'] = true;
             $result['info'] = $res['file'];
             $appObj = new ApkParser();
             if ($appObj->open($res['file'])) {
                 $re['package'] = $appObj->getPackage();
                 $re['versionname'] = $appObj->getVersionName();
                 $re['versioncode'] = $appObj->getVersionCode();
                 $re['appname'] = '洞头人才' . ' v' . $re['versionname'];
             }
             $re['size'] = $res['size'];
             $data = config('version');
             $result = array_merge($result, $data, $re);
             $this->ajaxReturn($result);
         } else {
             $this->error($res['msg']);
         }
     }
 }
Ejemplo n.º 5
0
 protected function _before_update(&$data, $option)
 {
     /************* 判断设备类型有没有被修改, 如果修改了类型,那么就删除原来的设备属性 ***************/
     // 先取出原来的类型是什么
     if (I('post.old_type_id') != $data['type_id']) {
         // 删除当前设备所有之前的属性
         $gaModel = M('DeviceAttr');
         $gaModel->where(array('device_id' => array('eq', $option['where']['id'])))->delete();
     }
     if (isset($_FILES['device_img']) && $_FILES['device_img']['error'] == 0) {
         $ret = uploadOne('device_img', 'devices', array(array(150, 150, 2)));
         if ($ret['ok'] == 1) {
             $data['device_img'] = $ret['images'][0];
             $data['sm_img'] = $ret['images'][1];
         } else {
             $this->error = $ret['error'];
             return FALSE;
         }
         deleteImage(array(I('post.old_device_img'), I('post.old_sm_img')));
     }
 }
Ejemplo n.º 6
0
 protected function _after_update($data, $option)
 {
     /**************** 处理商品的扩展分类 ********************/
     $eci = I('post.ext_cat_id');
     $gcModel = M('GoodsCat');
     // 先清除商品原扩展分类数据
     $gcModel->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     // 如果有新的数据就再添加一遍
     if ($eci) {
         foreach ($eci as $v) {
             // 如果分类为空就跳过处理下一个
             if (empty($v)) {
                 continue;
             }
             $gcModel->add(array('goods_id' => $option['where']['id'], 'cat_id' => $v));
         }
     }
     /************* 处理会员价格 ************************/
     $mpModel = M('MemberPrice');
     $mpModel->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     $mp = I('post.mp');
     if ($mp) {
         foreach ($mp as $k => $v) {
             if (empty($v)) {
                 continue;
             }
             $mpModel->add(array('goods_id' => $option['where']['id'], 'level_id' => $k, 'price' => $v));
         }
     }
     /************************* 处理商品图片的代码 ***********************/
     // 判断有没有图片
     if (hasImage('pics')) {
         $gpModel = M('GoodsPics');
         // 批量上传之后的图片数组,改造成每个图片一个一维数组的形式
         $pics = array();
         foreach ($_FILES['pics']['name'] as $k => $v) {
             if ($_FILES['pics']['size'][$k] == 0) {
                 continue;
             }
             $pics[] = array('name' => $v, 'type' => $_FILES['pics']['type'][$k], 'tmp_name' => $_FILES['pics']['tmp_name'][$k], 'error' => $_FILES['pics']['error'][$k], 'size' => $_FILES['pics']['size'][$k]);
         }
         // 在后面调用uploadOne方法时会使用$_FILES数组上传图片,所以我们要把我们处理好的数组赎给$_FILES这样上传时使用的就是我们处理好的数组
         $_FILES = $pics;
         // 循环每张图片一个一个的上传
         foreach ($pics as $k => $v) {
             $ret = uploadOne($k, 'Goods', array(array(150, 150)));
             if ($ret['ok'] == 1) {
                 $gpModel->add(array('goods_id' => $option['where']['id'], 'pic' => $ret['images'][0], 'sm_pic' => $ret['images'][1]));
             }
         }
     }
     /****************************** 修改商品属性的代码 ***************************/
     // 处理新属性
     $ga = I('post.ga');
     $ap = I('post.attr_price');
     $gaModel = M('GoodsAttr');
     if ($ga) {
         foreach ($ga as $k => $v) {
             foreach ($v as $k1 => $v1) {
                 if (empty($v1)) {
                     continue;
                 }
                 $price = isset($ap[$k][$k1]) ? $ap[$k][$k1] : '';
                 $gaModel->add(array('goods_id' => $option['where']['id'], 'attr_id' => $k, 'attr_value' => $v1, 'attr_price' => $price));
             }
         }
     }
     // 处理原属性
     $oldga = I('post.old_ga');
     $oldap = I('post.old_attr_price');
     // 循环所更新一遍所有的旧属性
     foreach ($oldga as $k => $v) {
         foreach ($v as $k1 => $v1) {
             // 要修改的字段
             $oldField = array('attr_value' => $v1);
             // 如果有对应的价格就把价格也修改
             if (isset($oldap[$k])) {
                 $oldField['attr_price'] = $oldap[$k][$k1];
             }
             $gaModel->where(array('id' => array('eq', $k1)))->save($oldField);
         }
     }
 }
Ejemplo n.º 7
0
 protected function _after_update($data, $option)
 {
     /*************** 处理商品的扩展分类 *******************/
     $exi = I('post.ext_cat_id');
     $gcModel = M('GoodsCat');
     //先清除商品原扩展的分类的数据
     $gcModel->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     //如果有新的数据有在添加一遍
     if ($exi) {
         foreach ($exi as $k => $v) {
             if (empty($v)) {
                 continue;
             }
             $gcModel->add(array('goods_id' => $option['where']['id'], 'cat_id' => $v));
         }
     }
     /********** 处理会员价格 ***********/
     $mpModel = M('MemberPrice');
     $mpModel->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     $mp = I('post.mp');
     if ($mp) {
         foreach ($mp as $k => $v) {
             if (empty($v)) {
                 continue;
             }
             $mpModel->add(array('goods_id' => $option['where']['id'], 'level_id' => $k, 'price' => $v));
         }
     }
     /*************** 处理商品的图片 ******************/
     //判断有没有图片
     if (hasImage('pics')) {
         $gpModel = M('GoodsPics');
         //批量上传
         $pics = array();
         foreach ($_FILES['pics']['name'] as $k => $v) {
             if ($_FILES['pics']['size'] == 0) {
                 continue;
             }
             $pics[] = array('name' => $v, 'type' => $_FILES['pics']['type'][$k], 'tmp_name' => $_FILES['pics']['tmp_name'][$k], 'error' => $_FILES['pics']['error'][$k], 'size' => $_FILES['pics']['size'][$k]);
         }
         // 在后面的调用uploadOne 方法会使用$_FILES 数组上传图片 我们要把我们处理好的数组给$_FILES 这样子上传时候就是使用我们处理好的数组
         $_FILES = $pics;
         foreach ($pics as $k => $v) {
             $ret = uploadOne($k, 'Goods', array(array(150, 150)));
             if ($ret['ok'] == 1) {
                 $gpModel->add(array('goods_id' => $data['id'], 'pic' => $ret['images'][0], 'sm_pic' => $ret['images'][1]));
             }
         }
     }
     /************** 处理商品属性 *************/
     //处理新属性
     $ga = I('post.ga');
     $ap = I('post.attr_price');
     $gaModel = M('GoodsAttr');
     foreach ($ga as $k => $v) {
         foreach ($v as $k1 => $v1) {
             if (empty($v1)) {
                 continue;
             }
             $price = isset($ap[$k][$k1]) ? $ap[$k][$k1] : '';
             $gaModel->add(array('goods_id' => $option['where']['id'], 'attr_id' => $k, 'attr_value' => $v1, 'attr_price' => $price));
         }
     }
     // 处理原属性
     $oldga = I('post.old_ga');
     $oldap = I('post.old_attr_price');
     //循环遍历更新一边所有的旧属性
     foreach ($oldga as $k => $v) {
         foreach ($v as $k1 => $v1) {
             # 要修改的字段
             $oldField = array('attr_value' => $v1);
             # 如果有对应的价格就把价格也修改
             if (isset($oldap[$k])) {
                 $oldField['attr_price'] = $oldap[$k][$k1];
             }
             $gaModel->where(array('id' => array('eq', $k1)))->save($oldField);
         }
     }
 }
Ejemplo n.º 8
0
 protected function _before_update(&$data, $option)
 {
     // 是否促销
     if (!isset($_POST['is_promote'])) {
         $data['is_promote'] = 0;
     }
     // 上传图片
     $ret = uploadOne('logo', 'Goods', array('sm' => array(80, 80)));
     if ($ret['ok']) {
         $data = array_merge($data, $ret['data']);
         // 删除商品的原图片
         $logo = $this->field('logo,sm_logo')->find(I('get.id'));
         $rp = C('IMG_rootPath');
         unlink($rp . $logo['logo']);
         unlink($rp . $logo['sm_logo']);
     } else {
         $this->error = $ret['error'];
         return false;
     }
 }
Ejemplo n.º 9
0
 public function portrait(int $uid)
 {
     $res = uploadOne(array('dir' => 'users/portrait', 'key' => 'image', 'thumb' => array(100, 100), 'save' => 'portrait_' . $uid, 'ext' => 'png'));
     if ($res['success']) {
         $this->saveInfo($uid, array('portrait' => $res['image']));
     }
     return $res;
 }