Example #1
0
        $data['size'] = $uploadList[0]['size'];
        $data['add_time'] = $_SERVER['REQUEST_TIME'];
        $data['ip'] = get_client_ip(1);
        $data['agent'] = $_SERVER['HTTP_USER_AGENT'];
        if ($type == 0) {
            list($data['width'], $data['height']) = getimagesize('../upload/' . $rand_num . $uploadList[0]['savename']);
        }
        $pigcms_id = M('Attachment_user')->add($data);
        if (!$pigcms_id) {
            unlink($upload_dir . $uploadList[0]['name']);
            json_return(1002, '图片上传失败1');
            exit;
        } else {
            $attachment_upload_type = option('config.attachment_upload_type');
            // 上传到又拍云服务器
            if ($attachment_upload_type == '1') {
                import('source.class.upload.upyunUser');
                upyunUser::upload('../upload/' . $rand_num . $uploadList[0]['savename'], '/' . $rand_num . $uploadList[0]['savename']);
            }
            json_return(0, array('id' => $pigcms_id, 'file' => getAttachmentUrl($rand_num . $uploadList[0]['savename'])));
            exit;
        }
    } else {
        json_return(1002, '图片上传失败2');
        exit;
    }
} else {
    json_return(1002, '图片上传失败3');
    exit;
}
echo ob_get_clean();
Example #2
0
 /**
  * 会员帐号首页
  */
 function index()
 {
     if (empty($this->user_session)) {
         $referer = url('account:index');
         redirect(url('account:login', array('referer' => $referer)));
         exit;
     }
     if (IS_POST) {
         $data = array();
         // 有上传图片时进行图片处理
         if (!empty($_FILES['file']) && $_FILES['file']['error'] != 4) {
             $img_path_str = '';
             // 会员店铺侧用的是商铺的id,作为目录,此处如果没有店铺id,则用会员uid
             if (isset($this->store_session['store_id'])) {
                 $img_path_str = sprintf("%09d", $this->store_session['store_id']);
             } else {
                 $img_path_str = sprintf("%09d", $this->user_session['uid']);
             }
             // 产生目录结构
             $rand_num = 'images/' . substr($img_path_str, 0, 3) . '/' . substr($img_path_str, 3, 3) . '/' . substr($img_path_str, 6, 3) . '/' . date('Ym', $_SERVER['REQUEST_TIME']) . '/';
             $upload_dir = './upload/' . $rand_num;
             if (!is_dir($upload_dir)) {
                 mkdir($upload_dir, 0777, true);
             }
             // 进行上传图片处理
             import('UploadFile');
             $upload = new UploadFile();
             $upload->maxSize = 1 * 1024 * 1024;
             $upload->allowExts = array('jpg', 'jpeg', 'png', 'gif');
             $upload->allowTypes = array('image/png', 'image/jpg', 'image/jpeg', 'image/gif');
             $upload->savePath = $upload_dir;
             $upload->saveRule = 'uniqid';
             if ($upload->upload()) {
                 $uploadList = $upload->getUploadFileInfo();
                 $add_result = $this->attachment_add($uploadList[0]['name'], $rand_num . $uploadList[0]['savename'], $uploadList[0]['size']);
                 if ($add_result['err_code']) {
                     unlink($upload_dir . $uploadList[0]['name']);
                 } else {
                     $data['avatar'] = $rand_num . $uploadList[0]['savename'];
                     $attachment_upload_type = option('config.attachment_upload_type');
                     // 上传到又拍云服务器
                     if ($attachment_upload_type == '1') {
                         import('source.class.upload.upyunUser');
                         upyunUser::upload('./upload/' . $data['avatar'], '/' . $rand_num . $uploadList[0]['savename']);
                     }
                 }
             }
         }
         $nickname = $_POST['nickname'];
         if (empty($nickname)) {
             echo json_encode(array('status' => false, 'msg' => '请填写昵称'));
             exit;
         }
         $data['nickname'] = $nickname;
         $data['intro'] = $_POST['intro'];
         M('User')->save_user(array('uid' => $this->user_session['uid']), $data);
         // 更新session数据
         $_SESSION['user']['nickname'] = $nickname;
         $_SESSION['user']['intro'] = $_POST['intro'];
         if (!empty($data['avatar'])) {
             $_SESSION['user']['avatar'] = getAttachmentUrl($data['avatar']);
         }
         echo json_encode(array('status' => true, 'msg' => '操作完成', 'data' => array('nexturl' => 'refresh')));
         exit;
     }
     //$user = M('User')->getUserById($this->user_session['uid']);
     //$this->assign('user', $user);
     $this->display();
 }
 public function audio_upload()
 {
     set_time_limit(0);
     $dom_id = $_POST['id'];
     if (!empty($_FILES['file']) && $_FILES['file']['error'] != 4) {
         $img_store_id = sprintf("%09d", $this->store_session['store_id']);
         $rand_num = 'audio/' . substr($img_store_id, 0, 3) . '/' . substr($img_store_id, 3, 3) . '/' . substr($img_store_id, 6, 3) . '/' . date('Ym', $_SERVER['REQUEST_TIME']) . '/';
         $upload_dir = './upload/' . $rand_num;
         if (!is_dir($upload_dir)) {
             mkdir($upload_dir, 0777, true);
         }
         import('UploadFile');
         $upload = new UploadFile();
         $upload->maxSize = $_POST['maxsize'] * 1024 * 1024;
         $upload->allowExts = array('amr', 'mp3');
         $upload->allowTypes = array('audio/mp3', 'audio/amr');
         $upload->savePath = $upload_dir;
         $upload->saveRule = 'uniqid';
         if ($upload->upload()) {
             $uploadList = $upload->getUploadFileInfo();
             $add_result = $this->attachment_add($uploadList[0]['name'], $rand_num . $uploadList[0]['savename'], $uploadList[0]['size'], 0, 1);
             if ($add_result['err_code']) {
                 die('{"jsonrpc":"2.0","result":{"error_code":' . $add_result['err_code'] . ',"err_msg":"' . $add_result['err_msg'] . '"},"id":"' . $dom_id . '"}');
             }
             // 上传到又拍云服务器
             $attachment_upload_type = option('config.attachment_upload_type');
             if ($attachment_upload_type == '1') {
                 import('source.class.upload.upyunUser');
                 upyunUser::upload('./upload/' . $rand_num . $uploadList[0]['savename'], '/' . $rand_num . $uploadList[0]['savename']);
             }
             die('{"jsonrpc":"2.0","result":{"error_code":0,"url":"' . getAttachmentUrl($rand_num . $uploadList[0]['savename']) . '","pigcms_id":' . $add_result['pigcms_id'] . '},"id":"' . $dom_id . '"}');
         } else {
             die('{"jsonrpc":"2.0","result":{"error_code":999,"err_msg":"' . $upload->getErrorMsg() . '"},"id":"' . $dom_id . '"}');
         }
     } else {
         die('{"jsonrpc":"2.0","result":{"error_code":999,"err_msg":"没有选择图片"},"id":"' . $dom_id . '"}');
     }
 }
Example #4
0
 public function adver_del()
 {
     $database_adver = D('Adver');
     $condition_adver['id'] = $_POST['id'];
     $now_adver = $database_adver->field(true)->where($condition_adver)->find();
     if ($database_adver->where($condition_adver)->delete()) {
         unlink('./upload/' . $now_adver['pic']);
         $attachment_upload_type = C('config.attachment_upload_type');
         // 删除又拍云服务器
         if ($attachment_upload_type == '1') {
             import('upyunUser', './source/class/upload/');
             upyunUser::delete('/' . $now_adver['pic']);
         }
         S('adver_list_' . $now_adver['cat_id'], NULL);
         // 清空缓存
         import('ORG.Util.Dir');
         Dir::delDirnotself('./cache');
         $this->success('删除成功');
     } else {
         $this->error('删除失败!请重试~');
     }
 }
Example #5
0
 public function brand_del()
 {
     $StoreBrand = M('StoreBrand');
     $brand_id = $this->_get('id', 'trim,intval');
     $now_brand = $StoreBrand->find($brand_id);
     if ($StoreBrand->delete($brand_id)) {
         //删除图片
         if ($now_brand['pic']) {
             unlink('./upload/' . $now_brand['pic']);
             // 上传到又拍云服务器
             $attachment_upload_type = C('config.attachment_upload_type');
             if ($attachment_upload_type == '1') {
                 import('upyunUser', './source/class/upload/');
                 upyunUser::delete('/' . $now_brand['pic']);
             }
         }
         $this->success('删除成功!');
     } else {
         $this->error('删除失败!请重试~');
     }
 }
Example #6
0
 public function category_edit()
 {
     $category = M('ProductCategory');
     if (IS_POST) {
         $cat_id = $this->_post('cat_id', 'trim,intval');
         $now_cat = $category->find($cat_id);
         if ($this->_post('property', 'trim') == '') {
             $this->frame_submit_tips(0, '分类属性不能为空!');
         }
         if ($_FILES['pic']['error'] != 4 || $_FILES['pcpic']['error'] != 4) {
             //上传图片
             $rand_num = date('Y/m', $_SERVER['REQUEST_TIME']);
             $upload_dir = './upload/category/' . $rand_num . '/';
             if (!is_dir($upload_dir)) {
                 mkdir($upload_dir, 0777, true);
             }
             import('ORG.Net.UploadFile');
             $upload = new UploadFile();
             $upload->maxSize = 10 * 1024 * 1024;
             $upload->allowExts = array('jpg', 'jpeg', 'png', 'gif');
             $upload->allowTypes = array('image/png', 'image/jpg', 'image/jpeg', 'image/gif');
             $upload->savePath = $upload_dir;
             $upload->saveRule = 'uniqid';
             if ($upload->upload()) {
                 $uploadList = $upload->getUploadFileInfo();
                 // 上传到又拍云服务器
                 $attachment_upload_type = C('config.attachment_upload_type');
                 if ($attachment_upload_type == '1') {
                     import('upyunUser', './source/class/upload/');
                     upyunUser::upload('./upload/category/' . $rand_num . '/' . $uploadList[0]['savename'], '/category/' . $rand_num . '/' . $uploadList[0]['savename']);
                 }
                 $j = 0;
                 if ($_FILES['pic']['error'] != 4) {
                     $_POST['cat_pic'] = 'category/' . $rand_num . '/' . $uploadList[$j]['savename'];
                     $j = 1;
                 }
                 if ($_FILES['pcpic']['error'] != 4) {
                     $_POST['cat_pc_pic'] = 'category/' . $rand_num . '/' . $uploadList[$j]['savename'];
                 }
             } else {
                 $this->frame_submit_tips(0, $upload->getErrorMsg());
             }
         }
         $data = array();
         $data['cat_fid'] = $this->_post('parent_id', 'trim,intval');
         $data['cat_name'] = $this->_post('name', 'trim');
         $data['cat_sort'] = $this->_post('order_by', 'trim,intval');
         $data['cat_status'] = $this->_post('status', 'trim,intval');
         $data['cat_desc'] = $this->_post('desc', 'trim');
         //商品属性类别
         //			$property_arr = $this->_post('property', 'trim');
         //			$property_arr = array_unique($property_arr);
         //			if (is_array($property_arr)) {
         //				$data['filter_attr'] = implode(',', $property_arr);
         //			} else {
         //				if (is_int($property_arr))
         //					$data['filter_attr'] = $property_arr;
         //			}
         $data['filter_attr'] = $this->_post('property', 'trim');
         $data['tag_str'] = join(',', $this->_post('tag', 'trim'));
         if (empty($data['tag_str'])) {
             $data['tag_str'] = '';
         }
         if ($_POST['cat_pic']) {
             $data['cat_pic'] = $_POST['cat_pic'];
         }
         if ($_POST['cat_pc_pic']) {
             $data['cat_pc_pic'] = $_POST['cat_pc_pic'];
         }
         if (!empty($data['cat_fid'])) {
             $data['cat_level'] = 2;
             $path = $category->where(array('cat_id' => $data['cat_fid']))->getField('cat_path');
             $data['cat_path'] = $path;
         } else {
             $data['cat_level'] = 1;
             $data['cat_path'] = 0;
         }
         if ($category->where(array('cat_id' => $cat_id))->save($data)) {
             if ($cat_id <= 9) {
                 $str_cat_id = '0' . $cat_id;
             } else {
                 $str_cat_id = $cat_id;
             }
             $path = $data['cat_path'] . ',' . $str_cat_id;
             $category->where(array('cat_id' => $cat_id))->save(array('cat_path' => $path));
             if ($_POST['cat_pic'] && $now_cat['cat_pic']) {
                 unlink('./upload/' . $now_cat['cat_pic']);
                 $attachment_upload_type = C('config.attachment_upload_type');
                 // 删除又拍云服务器
                 if ($attachment_upload_type == '1') {
                     import('upyunUser', './source/class/upload/');
                     upyunUser::delete('/' . $now_cat['cat_pic']);
                 }
             }
             if ($_POST['cat_pc_pic'] && $now_cat['cat_pc_pic']) {
                 unlink('./upload/' . $now_cat['cat_pc_pic']);
                 $attachment_upload_type = C('config.attachment_upload_type');
                 // 删除又拍云服务器
                 if ($attachment_upload_type == '1') {
                     import('upyunUser', './source/class/upload/');
                     upyunUser::delete('/' . $now_cat['cat_pc_pic']);
                 }
             }
             $this->frame_submit_tips(1, '修改成功!');
         } else {
             $this->frame_submit_tips(0, '修改失败!请重试~');
         }
     }
     $this->assign('bg_color', '#F3F3F3');
     $id = $this->_get('id', 'trim,intval');
     $categories = $category->where(array('cat_level' => 1, 'cat_status' => 1))->order('cat_sort ASC, cat_id ASC')->select();
     $category = $category->find($id);
     $category['cat_pic'] = getAttachmentUrl($category['cat_pic']);
     $category['cat_pc_pic'] = getAttachmentUrl($category['cat_pc_pic']);
     $this->assign('categories', $categories);
     $this->assign('category', $category);
     //获取属性类别的 所有属性
     $attr_list = D('SystemProductProperty')->get_property_list();
     $property_type = array();
     if ($category['filter_attr']) {
         $filter_attr = explode(",", $category['filter_attr']);
         //把多个筛选属性放到数组中
         foreach ($filter_attr as $k => $v) {
             if ($k != 0) {
                 break;
             }
             $property_type_id = M('SystemProductProperty')->where(array('pid' => $v))->find($v);
             $property_type[$k]['goods_type_list'] = D('SystemPropertyType')->get_PropertyType_list($property_type_id['property_type_id']);
             //取得每个属性的商品类型
             $property_type[$k]['filter_attr'] = $v;
             $attr_option = array();
             foreach ($attr_list[$property_type_id['property_type_id']] as $val) {
                 $attr_option[key($val)] = current($val);
             }
             $property_type[$k]['option'] = $attr_option;
             $property_type[$k]['option_selected_id'] = $v;
             $edit_type = 1;
         }
         $this->assign('filter_attr', $filter_attr);
     } else {
         //获取属性类别
         $property_type = M('SystemPropertyType')->where(array('type_status' => 1))->select();
         $edit_type = 2;
     }
     $system_property_type_list = D('system_property_type')->where(array('type_status' => 1))->select();
     $system_tag_list = D('system_tag')->select();
     $tag_arr = explode(',', $category['tag_str']);
     $tag_list = array();
     $system_tag_list_group = array();
     foreach ($system_tag_list as $tmp) {
         $system_tag_list_group[$tmp['tid']][] = $tmp;
         if (in_array($tmp['id'], $tag_arr)) {
             $tag_list[] = $tmp;
         }
     }
     $tag_str = '{';
     foreach ($system_tag_list_group as $key => $system_tag) {
         $tag_str .= $key . ':{';
         foreach ($system_tag as $i => $tmp) {
             if ($i != 0) {
                 $tag_str .= ',';
             }
             $name = str_replace('"', "'", $tmp['name']);
             $tag_str .= $tmp['id'] . ':"' . $name . '"';
         }
         $tag_str .= '},';
     }
     $tag_str .= '}';
     $this->assign('edit_type', $edit_type);
     //1:有属性 修改 2:无属性修改
     $this->assign('property_type', $property_type);
     $this->assign('system_property_type_list', $system_property_type_list);
     $this->assign('system_tag_list', $system_tag_list);
     $this->assign('system_tag_list_group', $system_tag_list_group);
     $this->assign('tag_str', $tag_str);
     $this->assign('tag_list', $tag_list);
     $this->display();
 }
Example #7
0
 private function upload()
 {
     import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     $upload->maxSize = 5 * 1024 * 1024;
     $upload->allowExts = array('jpg', 'jpeg', 'png', 'gif');
     $upload->allowTypes = array('image/png', 'image/jpg', 'image/jpeg', 'image/gif');
     $img_mer_id = sprintf("%09d", $this->system_session['id']);
     $rand_num = substr($img_mer_id, 0, 3) . '/' . substr($img_mer_id, 3, 3) . '/' . substr($img_mer_id, 6, 3);
     $upload_dir = "./upload/platform/{$rand_num}/";
     if (!is_dir($upload_dir)) {
         mkdir($upload_dir, 0777, true);
     }
     $upload->savePath = $upload_dir;
     // 设置附件上传目录
     if (!$upload->upload()) {
         // 上传错误提示错误信息
         $error = 1;
         $msg = $upload->getErrorMsg();
     } else {
         // 上传成功 获取上传文件信息
         $error = 0;
         $msg = $upload->getUploadFileInfo();
         // 上传到又拍云服务器
         $attachment_upload_type = C('config.attachment_upload_type');
         if ($attachment_upload_type == '1') {
             import('upyunUser', './source/class/upload/');
             foreach ($msg as $tmp) {
                 $remote_file = str_replace('./upload', '', $tmp['savepath'] . $tmp['savename']);
                 upyunUser::upload($tmp['savepath'] . $tmp['savename'], '/' . $remote_file);
             }
         }
     }
     return array('error' => $error, 'msg' => $msg);
 }
Example #8
0
 public function attachment()
 {
     if (empty($this->user_session)) {
         echo json_encode(array('status' => false, 'msg' => 'nologin'));
         exit;
     }
     if (!empty($_FILES['file']) && $_FILES['file']['error'] != 4) {
         $img_path_str = '';
         // 用会员uid
         $img_path_str = sprintf("%09d", $this->user_session['uid']);
         // 产生目录结构
         $rand_num = 'images/' . substr($img_path_str, 0, 3) . '/' . substr($img_path_str, 3, 3) . '/' . substr($img_path_str, 6, 3) . '/' . date('Ym', $_SERVER['REQUEST_TIME']) . '/';
         $upload_dir = './upload/' . $rand_num;
         if (!is_dir($upload_dir)) {
             mkdir($upload_dir, 0777, true);
         }
         // 进行上传图片处理
         import('UploadFile');
         $upload = new UploadFile();
         $upload->maxSize = 1 * 1024 * 1024;
         $upload->allowExts = array('jpg', 'jpeg', 'png', 'gif');
         $upload->allowTypes = array('image/png', 'image/jpg', 'image/jpeg', 'image/gif');
         $upload->savePath = $upload_dir;
         $upload->saveRule = 'uniqid';
         if ($upload->upload()) {
             $uploadList = $upload->getUploadFileInfo();
             $pigcms_id = $this->_attachmentAdd($uploadList[0]['name'], $rand_num . $uploadList[0]['savename'], $uploadList[0]['size']);
             if (!$pigcms_id) {
                 unlink($upload_dir . $uploadList[0]['name']);
                 echo json_encode(array('status' => false, 'msg' => '图片上传失败'));
                 exit;
             } else {
                 $attachment_upload_type = option('config.attachment_upload_type');
                 // 上传到又拍云服务器
                 if ($attachment_upload_type == '1') {
                     import('source.class.upload.upyunUser');
                     upyunUser::upload('./upload/' . $rand_num . $uploadList[0]['savename'], '/' . $rand_num . $uploadList[0]['savename']);
                 }
                 echo json_encode(array('status' => true, 'msg' => '上传成功', 'data' => array('id' => $pigcms_id, 'file' => getAttachmentUrl($rand_num . $uploadList[0]['savename']))));
                 exit;
             }
         } else {
             echo json_encode(array('status' => false, 'msg' => '图片上传失败'));
             exit;
         }
     } else {
         echo json_encode(array('status' => false, 'msg' => '未找到要上传文件'));
         exit;
     }
 }