/** * ajax上传图片 */ public function image_uploadOp() { // 判断图片数量是否超限 $model_album = Model('album'); $album_limit = $this->store_grade['sg_album_limit']; if ($album_limit > 0) { $album_count = $model_album->getCount(array('store_id' => 0)); if ($album_count >= $album_limit) { $error = L('store_goods_album_climit'); if (strtoupper(CHARSET) == 'GBK') { $error = Language::getUTF8($error); } exit(json_encode(array('error' => $error))); } } // $class_info = $model_album->getOne(array('store_id' => 0, 'is_default' => 1), 'album_class'); // 上传图片 $upload = new UploadFile(); $upload->set('default_dir', ATTACH_GOODS . DS . '0' . DS . $upload->getSysSetPath()); $upload->set('max_size', C('image_max_filesize')); $upload->set('thumb_width', GOODS_IMAGES_WIDTH); $upload->set('thumb_height', GOODS_IMAGES_HEIGHT); $upload->set('thumb_ext', GOODS_IMAGES_EXT); $upload->set('fprefix', '0'); $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png')); $result = $upload->upfile($_POST['id']); if (!$result) { if (strtoupper(CHARSET) == 'GBK') { $upload->error = Language::getUTF8($upload->error); } $output = array(); $output['error'] = $upload->error; $output = json_encode($output); exit($output); } $img_path = $upload->getSysSetPath() . $upload->file_name; $thumb_page = $upload->getSysSetPath() . $upload->thumb_image; // 取得图像大小 list($width, $height, $type, $attr) = getimagesize(UPLOAD_SITE_URL . '/' . ATTACH_GOODS . '/' . '0' . DS . $img_path); // 存入相册 $image = explode('.', $_FILES[$_POST['id']]["name"]); $insert_array = array(); $insert_array['apic_name'] = $image['0']; $insert_array['apic_tag'] = ''; $insert_array['aclass_id'] = 0; $insert_array['apic_cover'] = $img_path; $insert_array['apic_size'] = intval($_FILES[$_POST['id']]['size']); $insert_array['apic_spec'] = $width . 'x' . $height; $insert_array['upload_time'] = TIMESTAMP; $insert_array['store_id'] = '0'; $model_album->addPic($insert_array); $data = array(); $data['image'] = cthumb($img_path, 240, '0'); $data['filename'] = $img_path; // 整理为json格式 $output = json_encode($data); echo $output; exit; }
/** * 上传图片 */ public function image_uploadOp() { $lang = Language::getLangContent(); if ($_GET['upload_type'] == 'uploadedfile') { if ($_POST['file_id'] != '') { $model_store_goods = Model('flea'); $drop_stata = $model_store_goods->dropImageGoods(array('upload_id' => intval($_POST['file_id']))); } /** * 实例化json模型 */ /** * 上传图片 */ $upload = new UploadFile(); $upload_dir = ATTACH_MALBUM . DS . $_SESSION['member_id'] . DS; $upload->set('default_dir', $upload_dir . $upload->getSysSetPath()); $thumb_width = '240,1024'; $thumb_height = '2048,1024'; $upload->set('max_size', C('image_max_filesize')); $upload->set('thumb_width', $thumb_width); $upload->set('thumb_height', $thumb_height); $upload->set('fprefix', $_SESSION['member_id']); $upload->set('thumb_ext', '_240,_1024'); $result = $upload->upfile('file'); if ($result) { $_POST['pic'] = $upload->getSysSetPath() . $upload->file_name; $_POST['pic_thumb'] = $upload->getSysSetPath() . $upload->thumb_image; } else { // echo json_encode(array('state'=>'false','message'=>$lang['iswfupload_upload_pic_fail'])); echo "<script type='text/javascript'>alert('" . $upload->error . "');history.back();</script>"; exit; } $img_path = $_POST['pic']; /** * 取得图像大小 */ list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . DS . ATTACH_MALBUM . DS . $_SESSION['member_id'] . DS . $img_path); /** * 图片数据入库 */ $model_upload = Model('flea_upload'); $insert_array = array(); $image_type = array('goods_image' => 12, 'desc_image' => 13); //debug $insert_array['file_name'] = $_POST['pic']; $insert_array['file_thumb'] = $_POST['pic_thumb']; $insert_array['file_size'] = intval($_FILES['file']['size']); $insert_array['upload_time'] = time(); $insert_array['item_id'] = intval($_POST['item_id']); $insert_array['store_id'] = $_SESSION['member_id']; $insert_array['upload_type'] = $image_type['goods_image']; $result2 = $model_upload->add($insert_array); $data = array(); $data['file_id'] = $result2; $data['file_name'] = $_POST['pic_thumb']; $data['file_path'] = $_POST['pic_thumb']; $data['instance'] = 'goods_image'; $data['id'] = $_POST['id']; /** * 整理为json格式 */ $output = json_encode($data); echo "<script type='text/javascript'>window.parent.add_uploadedfile('" . $output . "');</script>"; } Tpl::showpage('flea_upload_image', 'null_layout'); }
/** * ajax图片上传 */ public function image_uploadOp() { $ap_id = intval($_POST['apid']); /** * 相册 */ $model = Model(); $default_class = $model->table('sns_albumclass')->where(array('member_id' => $_SESSION['member_id'], 'is_default' => 1))->find(); if (empty($default_class)) { // 验证时候存在买家秀相册,不存在添加。 $default_class = array(); $default_class['ac_name'] = Language::get('sns_buyershow'); $default_class['member_id'] = $this->master_id; $default_class['ac_des'] = Language::get('sns_buyershow_album_des'); $default_class['ac_sort'] = '255'; $default_class['is_default'] = 1; $default_class['upload_time'] = time(); $default_class['ac_id'] = $model->table('sns_albumclass')->insert($default_class); } // 验证图片数量 $count = $model->table('sns_albumpic')->where(array('member_id' => $_SESSION['member_id']))->count(); if (C('malbum_max_sum') != 0 && $count >= C('malbum_max_sum')) { $output = array(); $output['error'] = Language::get('sns_upload_img_max_num_error'); $output = json_encode($output); echo $output; die; } /** * 上传图片 */ $upload = new UploadFile(); if ($ap_id > 0) { $pic_info = $model->table('sns_albumpic')->find($ap_id); if (!empty($pic_info)) { $upload->set('file_name', $pic_info['ap_cover']); } // 原图存在设置图片名称为原图名称 } $upload_dir = ATTACH_MALBUM . DS . $_SESSION['member_id'] . DS; $upload->set('default_dir', $upload_dir . $upload->getSysSetPath()); $thumb_width = '240,1024'; $thumb_height = '2048,1024'; $upload->set('max_size', C('image_max_filesize')); $upload->set('thumb_width', $thumb_width); $upload->set('thumb_height', $thumb_height); $upload->set('fprefix', $_SESSION['member_id']); $upload->set('thumb_ext', '_240,_1024'); $result = $upload->upfile(trim($_POST['id'])); if (!$result) { if (strtoupper(CHARSET) == 'GBK') { $upload->error = Language::getUTF8($upload->error); } $output = array(); $output['error'] = $upload->error; $output = json_encode($output); echo $output; die; } if ($ap_id <= 0) { // 如果原图存在,则不需要在插入数据库 $img_path = $upload->getSysSetPath() . $upload->file_name; list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . DS . ATTACH_MALBUM . DS . $_SESSION['member_id'] . DS . $img_path); $image = explode('.', $_FILES[trim($_POST['id'])]["name"]); if (strtoupper(CHARSET) == 'GBK') { $image['0'] = Language::getGBK($image['0']); } $insert = array(); $insert['ap_name'] = $image['0']; $insert['ac_id'] = $default_class['ac_id']; $insert['ap_cover'] = $img_path; $insert['ap_size'] = intval($_FILES[trim($_POST['id'])]['size']); $insert['ap_spec'] = $width . 'x' . $height; $insert['upload_time'] = time(); $insert['member_id'] = $_SESSION['member_id']; $insert['ap_type'] = 1; $insert['item_id'] = intval($_POST['sid']); $result = $model->table('sns_albumpic')->insert($insert); } $data = array(); $data['file_name'] = $ap_id > 0 ? $pic_info['ap_cover'] : $upload->getSysSetPath() . $upload->thumb_image; $data['file_id'] = $ap_id > 0 ? $pic_info['ap_id'] : $result; /** * 整理为json格式 */ $output = json_encode($data); echo $output; die; }
/** * 上传图片 * * @param * @return */ public function swfuploadOp() { /** * 读取语言包 */ Language::read('sns_home'); $lang = Language::getLangContent(); $member_id = $_SESSION['member_id']; $class_id = intval($_POST['category_id']); if ($member_id <= 0 && $class_id <= 0) { echo json_encode(array('state' => 'false', 'message' => Language::get('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"])); exit; } $model = Model(); // 验证图片数量 $count = $model->table('sns_albumpic')->where(array('member_id' => $member_id))->count(); if (C('malbum_max_sum') != 0 && $count >= C('malbum_max_sum')) { echo json_encode(array('state' => 'false', 'message' => Language::get('sns_upload_img_max_num_error'), 'origin_file_name' => $_FILES["file"]["name"])); exit; } /** * 上传图片 */ $upload = new UploadFile(); $upload_dir = ATTACH_MALBUM . DS . $member_id . DS; $upload->set('default_dir', $upload_dir . $upload->getSysSetPath()); $thumb_width = '240,1024'; $thumb_height = '2048,1024'; $upload->set('max_size', C('image_max_filesize')); $upload->set('thumb_width', $thumb_width); $upload->set('thumb_height', $thumb_height); $upload->set('fprefix', $member_id); $upload->set('thumb_ext', '_240,_1024'); $result = $upload->upfile('file'); if (!$result) { echo json_encode(array('state' => 'false', 'message' => Language::get('sns_upload_pic_fail'), 'origin_file_name' => $_FILES["file"]["name"])); exit; } $img_path = $upload->getSysSetPath() . $upload->file_name; list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . DS . ATTACH_MALBUM . DS . $member_id . DS . $img_path); $image = explode('.', $_FILES["file"]["name"]); if (strtoupper(CHARSET) == 'GBK') { $image['0'] = Language::getGBK($image['0']); } $insert = array(); $insert['ap_name'] = $image['0']; $insert['ac_id'] = $class_id; $insert['ap_cover'] = $img_path; $insert['ap_size'] = intval($_FILES['file']['size']); $insert['ap_spec'] = $width . 'x' . $height; $insert['upload_time'] = time(); $insert['member_id'] = $member_id; $result = $model->table('sns_albumpic')->insert($insert); $data = array(); $data['file_id'] = $result; $data['file_name'] = $img_path; $data['origin_file_name'] = $_FILES["file"]["name"]; $data['file_path'] = $img_path; $data['file_url'] = snsThumb($img_path, 240); $data['state'] = 'true'; /** * 整理为json格式 */ $output = json_encode($data); echo $output; }
/** * 店铺幻灯片ajax上传 */ public function silde_image_uploadOp() { $upload = new UploadFile(); $upload->set('default_dir', ATTACH_SLIDE . DS . $upload->getSysSetPath()); $upload->set('max_size', C('image_max_filesize')); $result = $upload->upfile($_POST['id']); $output = array(); if (!$result) { /** * 转码 */ if (strtoupper(CHARSET) == 'GBK') { $upload->error = Language::getUTF8($upload->error); } $output['error'] = $upload->error; echo json_encode($output); die; } $img_path = $upload->getSysSetPath() . $upload->file_name; /** * 模型实例化 */ $model_upload = Model('upload'); if (intval($_POST['file_id']) > 0) { $file_info = $model_upload->getOneUpload($_POST['file_id']); @unlink(ATTACH_SLIDE . DS . $file_info['file_name']); $update_array = array(); $update_array['upload_id'] = intval($_POST['file_id']); $update_array['file_name'] = $img_path; $update_array['file_size'] = $_FILES[$_POST['id']]['size']; $model_upload->update($update_array); $output['file_id'] = intval($_POST['file_id']); $output['id'] = $_POST['id']; $output['file_name'] = $img_path; echo json_encode($output); die; } else { /** * 图片数据入库 */ $insert_array = array(); $insert_array['file_name'] = $img_path; $insert_array['upload_type'] = '7'; $insert_array['file_size'] = $_FILES[$_POST['id']]['size']; $insert_array['store_id'] = $_SESSION['store_id']; $insert_array['upload_time'] = time(); $result = $model_upload->add($insert_array); if (!$result) { @unlink(ATTACH_SLIDE . DS . $img_path); $output['error'] = Language::get('store_slide_upload_fail', 'UTF-8'); echo json_encode($output); die; } $output['file_id'] = $result; $output['id'] = $_POST['id']; $output['file_name'] = $img_path; echo json_encode($output); die; } }
/** * 上传图片 * */ public function image_uploadOp() { $store_id = $_SESSION['store_id']; if (!empty($_POST['category_id'])) { $category_id = intval($_POST['category_id']); } else { $error = '上传 图片失败'; if (strtoupper(CHARSET) == 'GBK') { $error = Language::getUTF8($error); } $data['state'] = 'false'; $data['message'] = $error; $data['origin_file_name'] = $_FILES["file"]["name"]; echo json_encode($data); exit; } // 判断图片数量是否超限 $album_limit = $this->store_grade['sg_album_limit']; if ($album_limit > 0) { $album_count = Model('album')->getCount(array('store_id' => $store_id)); if ($album_count >= $album_limit) { // 目前并不出该提示,而是提示上传0张图片 $error = L('store_goods_album_climit'); if (strtoupper(CHARSET) == 'GBK') { $error = Language::getUTF8($error); } $data['state'] = 'false'; $data['message'] = $error; $data['origin_file_name'] = $_FILES["file"]["name"]; $data['state'] = 'true'; echo json_encode($data); exit; } } /** * 上传图片 */ $upload = new UploadFile(); $upload->set('default_dir', ATTACH_GOODS . DS . $store_id . DS . $upload->getSysSetPath()); $upload->set('max_size', C('image_max_filesize')); $upload->set('thumb_width', GOODS_IMAGES_WIDTH); $upload->set('thumb_height', GOODS_IMAGES_HEIGHT); $upload->set('thumb_ext', GOODS_IMAGES_EXT); $upload->set('fprefix', $store_id); $result = $upload->upfile('file'); if ($result) { $pic = $upload->getSysSetPath() . $upload->file_name; $pic_thumb = $upload->getSysSetPath() . $upload->thumb_image; } else { // 目前并不出该提示 $error = $upload->error; if (strtoupper(CHARSET) == 'GBK') { $error = Language::getUTF8($error); } $data['state'] = 'false'; $data['message'] = $error; $data['origin_file_name'] = $_FILES["file"]["name"]; echo json_encode($data); exit; } list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . DS . ATTACH_GOODS . DS . $store_id . DS . $pic); $image = explode('.', $_FILES["file"]["name"]); if (strtoupper(CHARSET) == 'GBK') { $image['0'] = Language::getGBK($image['0']); } $insert_array = array(); $insert_array['apic_name'] = $image['0']; $insert_array['apic_tag'] = ''; $insert_array['aclass_id'] = $category_id; $insert_array['apic_cover'] = $pic; $insert_array['apic_size'] = intval($_FILES['file']['size']); $insert_array['apic_spec'] = $width . 'x' . $height; $insert_array['upload_time'] = time(); $insert_array['store_id'] = $store_id; $result = Model('upload_album')->add($insert_array); $data = array(); $data['file_id'] = $result; $data['file_name'] = $pic; $data['origin_file_name'] = $_FILES["file"]["name"]; $data['file_path'] = $pic; $data['instance'] = $_GET['instance']; $data['state'] = 'true'; /** * 整理为json格式 */ $output = json_encode($data); echo $output; }
/** * 批量导入图片 * * @param * @return */ public function import_pic_uploadOp() { /** * 读取语言包 */ Language::read('common', 'iswfupload'); $lang = Language::getLangContent('UTF-8'); /** * 检查图片是否是商品图片 */ $model_upload = Model('upload'); if ($_POST['Filename'] == '') { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_miss_file'])); exit; } $upload_list = $model_upload->getUploadList(array('file_name' => substr($_POST['Filename'], 0, strlen($_POST['Filename']) - 4))); if (empty($upload_list) or !is_array($upload_list)) { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_image'] . $_POST['Filename'] . $lang['iswfupload_not_goods_image'])); exit; } $upload_info = $upload_list[0]; if (empty($upload_info) or !is_array($upload_info)) { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_image'] . $_POST['Filename'] . $lang['iswfupload_not_goods_image'])); exit; } if ($upload_info['upload_type'] != '2') { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_image'] . $_POST['Filename'] . $lang['iswfupload_not_goods_image'])); exit; } if (empty($upload_info['store_id'])) { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_upload_pictext'] . $_POST['Filename'] . $lang['iswfupload_upload_noprodpic'])); exit; } $store_id = $upload_info['store_id']; /** * 上传图片 */ $upload = new UploadFile(); $upload_dir = ATTACH_GOODS . DS . $store_id; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0755); } $upload = new UploadFile(); $upload->set('default_dir', $upload_dir . DS . $upload->getSysSetPath()); $upload->set('max_size', C('image_max_filesize')); $thumb_width = C('thumb_small_width') . ',' . C('thumb_mid_width') . ',' . C('thumb_max_width') . ',' . C('thumb_tiny_width') . ',240'; $thumb_height = C('thumb_small_height') . ',' . C('thumb_mid_height') . ',' . C('thumb_max_height') . ',' . C('thumb_tiny_height') . ',50000'; $upload->set('thumb_width', $thumb_width); $upload->set('thumb_height', $thumb_height); $upload->set('thumb_ext', '_small,_mid,_max,_tiny,_240x240'); $upload->set('new_ext', 'jpg'); /** * 设置允许上传的文件类型 */ $result = $upload->upfile('Filedata'); if (!$result) { echo json_encode(array('state' => 'false', 'message' => $upload->error)); exit; } /** * 取得图像大小 */ list($width, $height, $type, $attr) = getimagesize(BasePath . DS . 'upload' . DS . 'store' . DS . 'goods' . DS . $store_id . DS . $upload->getSysSetPath() . $upload->file_name); if (C('ftp_open') && C('thumb.save_type') == 3) { import('function.ftp'); $img_path = $upload->getSysSetPath() . $upload->file_name; if ($_url = remote_ftp(ATTACH_GOODS . DS . $store_id, $img_path, false)) { $image_cover = $_url . '/'; } } /** * 模型实例化 */ $model_upload_album = Model('upload_album'); /** * 图片数据入库 */ $image = explode('.', $_FILES["Filedata"]["name"]); $insert_array = array(); $insert_array['apic_name'] = $image['0']; $insert_array['apic_tag'] = ''; $insert_array['aclass_id'] = $_POST['category_id']; $insert_array['apic_cover'] = $img_path; $insert_array['apic_size'] = intval($_FILES['Filedata']['size']); $insert_array['apic_spec'] = $width . 'x' . $height; $insert_array['upload_time'] = time(); $insert_array['store_id'] = $store_id; $result = $model_upload_album->add($insert_array); /** * 图片数据入库 */ $insert_array = array(); $insert_array['file_name'] = $upload->getSysSetPath() . $upload->file_name; $insert_array['file_thumb'] = $upload->getSysSetPath() . $upload->thumb_image; $insert_array['file_wm'] = $_POST['pic_wm']; $insert_array['file_size'] = $_FILES['Filedata']['size']; $insert_array['upload_time'] = time(); foreach ($upload_list as $val) { $insert_array['upload_id'] = $val['upload_id']; $result = $model_upload->update($insert_array); if ($result) { if ($result) { $data = array(); $data['file_id'] = $val['upload_id']; $data['file_name'] = $upload->getSysSetPath() . $upload->file_name; $data['file_path'] = $upload->getSysSetPath() . $upload->file_name; /** * 整理为json格式 */ $output = json_encode($data); echo $output; } else { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_update_fail'])); exit; } } else { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_upload_fail'])); exit; } } }
/** * 上传图片 * * @param * @return */ public function swfuploadOp() { /** * 读取语言包 */ Language::read('iswfupload'); $lang = Language::getLangContent(); // 图片上传session传递 if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } /** * 上传图片 */ $upload = new UploadFile(); $upload_dir = ATTACH_GOODS . DS . $_SESSION['store_id'] . DS; // /** // * 上传图片前,对卖家的使用空间进行判断 // */ // $model_store_grade = Model('store_grade'); // $store_grade = $model_store_grade->getGradeShopList(array('store_id'=>$_SESSION['store_id'])); // if(intval($store_grade[0]['sg_space_limit']) != 0) { // $use_space = number_format((getDirSize($upload_dir)/1024/1024),2,'.',''); // $grade_space = number_format($store_grade[0]['sg_space_limit'],2,'.',''); // if($use_space >= $grade_space) { // echo json_encode(array('state'=>'false','message'=>$lang['iswfupload_reach_limit'].$grade_space.$lang['iswfupload_upgrade'])); // exit(); // } // } /** * 设置上传图片路径 */ $upload->set('default_dir', $upload_dir . $upload->getSysSetPath()); if (trim($_GET['instance']) == 'goods_image') { $upload->set('ifresize', true); } $result = $upload->upfile('Filedata'); if (empty($upload->error_msg)) { if (trim($_GET['instance']) == 'goods_image') { $_POST['pic'] = $upload->getSysSetPath() . $result['image']; $_POST['pic_thumb'] = $upload->getSysSetPath() . $result['image_thumb']; $model_store_wm = Model('store_watermark'); /** * 获取会员水印设置 */ $store_wm_info = $model_store_wm->getOneStoreWMByStoreId($_SESSION['store_id']); /** * 是否开启是否开启水印 */ if ($store_wm_info['wm_is_open']) { require_once BasePath . DS . 'framework' . DS . 'libraries' . DS . 'gdimage.php'; $gd_image = new GdImage(); $gd_image->setWatermark($store_wm_info); $gd_image->create(ATTACH_GOODS . DS . $_SESSION['store_id'] . DS . $upload->getSysSetPath() . $result['image_thumb']); //缩略图加水印 $gd_image->set('save_file', ATTACH_GOODS . DS . $_SESSION['store_id'] . DS . $upload->getSysSetPath() . 'wm_' . $result['image']); $gd_image->set('src_image_name', ATTACH_GOODS . DS . $_SESSION['store_id'] . DS . $upload->getSysSetPath() . $result['image']); $gd_create = $gd_image->create(); //生成有水印的大图 if ($gd_create) { $_POST['pic_wm'] = $upload->getSysSetPath() . 'wm_' . $result['image']; } } unset($store_wm_info); } else { $_POST['pic'] = $upload->getSysSetPath() . $result; } } else { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_upload_pic_fail'])); exit; } /** * 模型实例化 */ $model_upload = Model('upload'); /** * 图片数据入库 */ $insert_array = array(); $image_type = array('goods_image' => 2, 'desc_image' => 3); $insert_array['file_name'] = $_POST['pic']; $insert_array['file_thumb'] = empty($_POST['pic_thumb']) ? $_POST['pic'] : $_POST['pic_thumb']; $insert_array['file_wm'] = $_POST['pic_wm']; $insert_array['file_size'] = intval($_FILES['Filedata']['size']); $insert_array['upload_time'] = time(); $insert_array['item_id'] = intval($_POST['item_id']); $insert_array['store_id'] = $_SESSION['store_id']; $insert_array['upload_type'] = $image_type[trim($_GET['instance'])]; $result = $model_upload->add($insert_array); if ($result) { if ($_POST['pic_wm']) { $_POST['pic'] = $_POST['pic_wm']; } $data = array(); $data['file_id'] = $result; $data['file_name'] = $_POST['pic']; $data['file_path'] = $_POST['pic']; $data['instance'] = $_GET['instance']; /** * 整理为json格式 */ $output = json_encode($data); echo $output; } }
/** * 上传图片 * * @param * @return */ public function swfuploadOp() { /** * 读取语言包 */ Language::read('iswfupload'); $lang = Language::getLangContent(); if (isset($_POST["PHPSESSID"])) { session_id($_POST["PHPSESSID"]); } $sid = intval($_POST['sid']); if (!empty($_POST['category_id']) && !empty($_POST['sid'])) { $category_id = intval($_POST['category_id']); $store_id = $sid; } else { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_upload_pic_fail'])); exit; } //判断图片数量是否超限 $model = Model(); $store_grade = ($setting = F('store_grade')) ? $setting : H('store_grade', true, 'file'); $grade_id = $model->table('store')->getfby_store_id($store_id, 'grade_id'); $album_limit = $store_grade[$grade_id]['sg_album_limit']; $album_count = $model->table('album_pic')->where(array('store_id' => $store_id))->count(); if ($album_count >= $album_limit) { //目前并不出该提示,而是提示上传0张图片 $error = Language::get('store_goods_album_climit'); if (strtoupper(CHARSET) == 'GBK') { $error = Language::getUTF8($error); } exit(json_encode(array('state' => 'false', 'message' => $error))); } /** * 上传图片 */ $upload = new UploadFile(); $upload_dir = ATTACH_GOODS . DS . $store_id . DS; $upload->set('default_dir', $upload_dir . $upload->getSysSetPath()); if (trim($_GET['instance']) == 'goods_image') { $thumb_width = C('thumb_small_width') . ',' . C('thumb_mid_width') . ',' . C('thumb_max_width') . ',' . C('thumb_tiny_width') . ',240'; $thumb_height = C('thumb_small_height') . ',' . C('thumb_mid_height') . ',' . C('thumb_max_height') . ',' . C('thumb_tiny_height') . ',1024'; $upload->set('max_size', C('image_max_filesize')); $upload->set('thumb_width', $thumb_width); $upload->set('thumb_height', $thumb_height); $upload->set('fprefix', $sid); $upload->set('thumb_ext', '_small,_mid,_max,_tiny,_240x240'); } $result = $upload->upfile('Filedata'); if ($result) { $_POST['pic'] = $upload->getSysSetPath() . $upload->file_name; $_POST['pic_thumb'] = $upload->getSysSetPath() . $upload->thumb_image; } else { //目前并不出该提示 echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_upload_pic_fail'])); exit; } $img_path = $_POST['pic']; list($width, $height, $type, $attr) = getimagesize(BasePath . DS . 'upload' . DS . 'store' . DS . 'goods' . DS . $store_id . DS . $img_path); if (C('ftp_open') && C('thumb.save_type') == 3) { import('function.ftp'); if (!remote_ftp(ATTACH_GOODS . DS . $sid, $img_path)) { echo json_encode(array('state' => 'false', 'message' => $lang['iswfupload_upload_pic_fail'])); exit; } } $model_upload_album = Model('upload_album'); $image = explode('.', $_FILES["Filedata"]["name"]); if (strtoupper(CHARSET) == 'GBK') { $image['0'] = Language::getGBK($image['0']); } $insert_array = array(); $insert_array['apic_name'] = $image['0']; $insert_array['apic_tag'] = ''; $insert_array['aclass_id'] = $category_id; $insert_array['apic_cover'] = $img_path; $insert_array['apic_size'] = intval($_FILES['Filedata']['size']); $insert_array['apic_spec'] = $width . 'x' . $height; $insert_array['upload_time'] = time(); $insert_array['store_id'] = $store_id; $result = $model_upload_album->add($insert_array); $data = array(); $data['file_id'] = $result; $data['file_name'] = $_POST['pic']; $data['file_path'] = $_POST['pic']; $data['instance'] = $_GET['instance']; $data['state'] = 'true'; /** * 整理为json格式 */ $output = json_encode($data); echo $output; }
/** * 上传图片 */ public function image_uploadOp() { //判断图片数量是否超限 $model = Model(); $store_grade = ($setting = F('store_grade')) ? $setting : H('store_grade', true, 'file'); $grade_id = $model->table('store')->getfby_store_id($_SESSION['store_id'], 'grade_id'); $album_limit = $store_grade[$grade_id]['sg_album_limit']; $album_count = $model->table('album_pic')->where(array('store_id' => $_SESSION['store_id']))->count(); if ($album_count >= $album_limit) { $error = Language::get('store_goods_album_climit'); if (strtoupper(CHARSET) == 'GBK') { $error = Language::getUTF8($error); } exit(json_encode(array('error' => $error))); } $lang = Language::getLangContent(); $class_info = Model('album_class')->where(array('store_id' => $_SESSION['store_id'], 'is_default' => 1))->find(); /** * 上传图片 */ $upload = new UploadFile(); $upload->set('default_dir', ATTACH_GOODS . DS . $_SESSION['store_id'] . DS . $upload->getSysSetPath()); $upload->set('max_size', C('image_max_filesize')); $thumb_width = C('thumb_tiny_width') . ',' . C('thumb_small_width') . ',' . C('thumb_mid_width') . ',' . C('thumb_max_width') . ',240'; $thumb_height = C('thumb_tiny_height') . ',' . C('thumb_small_height') . ',' . C('thumb_mid_height') . ',' . C('thumb_max_height') . ',1024'; $upload->set('thumb_width', $thumb_width); $upload->set('thumb_height', $thumb_height); $upload->set('thumb_ext', '_tiny,_small,_mid,_max,_240x240'); $upload->set('fprefix', $_SESSION['store_id']); $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png')); $result = $upload->upfile($_POST['id']); if (!$result) { if (strtoupper(CHARSET) == 'GBK') { $upload->error = Language::getUTF8($upload->error); } $output = array(); $output['error'] = $upload->error; $output = json_encode($output); exit($output); } $img_path = $upload->getSysSetPath() . $upload->file_name; /** * 取得图像大小 */ list($width, $height, $type, $attr) = getimagesize(BasePath . '/upload/store/goods/' . $_SESSION['store_id'] . DS . $img_path); /** * 存入相册 */ $model_upload_album = Model('upload_album'); $image = explode('.', $_FILES[$_POST['id']]["name"]); $insert_array = array(); $insert_array['apic_name'] = $image['0']; $insert_array['apic_tag'] = ''; $insert_array['aclass_id'] = $class_info['aclass_id']; $insert_array['apic_cover'] = $img_path; $insert_array['apic_size'] = intval($_FILES[$_POST['id']]['size']); $insert_array['apic_spec'] = $width . 'x' . $height; $insert_array['upload_time'] = time(); $insert_array['store_id'] = $_SESSION['store_id']; $result1 = $model_upload_album->add($insert_array); $data = array(); $data['file_name'] = $upload->getSysSetPath() . $upload->thumb_image; $data['image_cover'] = SiteUrl . DS . ATTACH_GOODS . DS . $_SESSION['store_id'] . '/'; if (C('ftp_open') && C('thumb.save_type') == 3) { import('function.ftp'); if ($_url = remote_ftp(ATTACH_GOODS . DS . $_SESSION['store_id'], $img_path)) { $data['image_cover'] = $_url . '/'; } } /** * 整理为json格式 */ $output = json_encode($data); echo $output; die; }