Example #1
0
 public function add()
 {
     if (I('brand-name') == null) {
         $this->display();
     } else {
         $brandName = I('brand-name');
         $brandLogo = $_FILES['brand-logo'];
         $img_name = "brand/pic/" . uniqid() . strrchr($brandLogo['name'], 46);
         $filepath = UploadBeforeOss($brandLogo);
         //上传图片到服务器,获取服务器文件路径
         $brandLogic = new l\BrandLogic();
         $logoUrl = null;
         if ($brandLogo != '') {
             //上传文件到OSS
             if (ImgOssUpload($img_name, $filepath)) {
                 $logoUrl = C('OSS_FILE_PREFIX') . '/' . $img_name;
             } else {
                 $data['status'] = 300;
                 $data['message'] = '图片上传失败';
                 $data['error_code'] = 10002;
                 $this->ajaxReturn($data, 'JSON');
             }
         }
         $result = $brandLogic->addBrand($brandName, $logoUrl);
         $data['status'] = $result['status'];
         $data['message'] = $result['message'];
         S('brands', NULL);
         $this->ajaxReturn($data, 'JSON');
     }
 }