コード例 #1
0
ファイル: iswfupload.php プロジェクト: dw250100785/shopnc
 /**
  * 批量导入图片
  *
  * @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;
         }
     }
 }
コード例 #2
0
ファイル: store_album.php プロジェクト: noikiy/ecmall
 /**
  * 替换图片
  */
 public function replace_image_uploadOp()
 {
     $lang = Language::getLangContent();
     Tpl::output('id', intval($_GET['id']));
     if (chksubmit()) {
         /**
          * 实例化相册类
          */
         $model_album = Model('album');
         $param = array();
         $param['field'] = array('apic_id', 'store_id');
         $param['value'] = array(intval($_POST['id']), $_SESSION['store_id']);
         $apic_info = $model_album->getOnePicById($param);
         if (substr(strrchr($apic_info['apic_cover'], "."), 1) != substr(strrchr($_FILES["file"]["name"], "."), 1)) {
             echo "<script type='text/javascript'>window.parent.img_replace_error('" . Language::get('album_replace_same_type') . "');</script>";
             Tpl::showpage('replace_image', 'null_layout');
             die;
         }
         $pic_cover = implode(DS, explode(DS, $apic_info['apic_cover'], -1));
         //文件路径
         $tmpvar = explode(DS, $apic_info['apic_cover']);
         $pic_name = array_pop($tmpvar);
         //文件名称
         /**
          * 上传图片
          */
         $upload = new UploadFile();
         $upload->set('default_dir', ATTACH_GOODS . DS . $_SESSION['store_id'] . DS . $pic_cover);
         $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') . ',1024';
         $upload->set('thumb_width', $thumb_width);
         $upload->set('thumb_height', $thumb_height);
         $upload->set('thumb_ext', '_small,_mid,_max,_tiny,_240x240');
         $upload->set('file_name', $pic_name);
         $return = $upload->upfile('file');
         if (!$return) {
             echo "<script type='text/javascript'>window.parent.img_replace_error('" . $upload->error . "');</script>";
             Tpl::showpage('replace_image', 'null_layout');
             die;
         }
         /**
          * 取得图像大小
          */
         list($width, $height, $type, $attr) = getimagesize(BasePath . DS . 'upload' . DS . 'store' . DS . 'goods' . DS . $_SESSION['store_id'] . DS . $apic_info['apic_cover']);
         if (C('ftp_open') && C('thumb.save_type') == 3) {
             import('function.ftp');
             $image_full_path = ATTACH_GOODS . DS . $_SESSION['store_id'] . DS . $apic_info['apic_cover'];
             file_put_contents('f:\\b.txt', $image_full_path);
             $_ext = '.' . get_image_type($image_full_path);
             if (!ftpcmd('error')) {
                 ftpcmd('delete', $image_full_path);
             }
             if (!ftpcmd('error')) {
                 ftpcmd('delete', $image_full_path . '_max' . $_ext);
             }
             if (!ftpcmd('error')) {
                 ftpcmd('delete', $image_full_path . '_mid' . $_ext);
             }
             if (!ftpcmd('error')) {
                 ftpcmd('delete', $image_full_path . '_small' . $_ext);
             }
             if (!ftpcmd('error')) {
                 ftpcmd('delete', $image_full_path . '_tiny' . $_ext);
             }
             if (!ftpcmd('error')) {
                 ftpcmd('delete', $image_full_path . '_240x240' . $_ext);
             }
             remote_ftp(ATTACH_GOODS . DS . $_SESSION['store_id'], $apic_info['apic_cover']);
         }
         /**
          * 更新图片分类
          */
         $param = array();
         $param['apic_size'] = intval($_FILES['file']['size']);
         $param['apic_spec'] = $width . 'x' . $height;
         $return = $model_album->updatePic($param, array('apic_id' => intval($_POST['id'])));
         Tpl::output('id', intval($_POST['id']));
         echo "<script type='text/javascript'>window.parent.img_refresh('" . intval($_POST['id']) . "');</script>";
     }
     Tpl::showpage('replace_image', 'null_layout');
 }
コード例 #3
0
ファイル: swfupload2.php プロジェクト: noikiy/ecmall
 /**
  * 上传图片
  *
  * @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;
 }
コード例 #4
0
ファイル: store_goods.php プロジェクト: dw250100785/shopnc
 /**
  * 上传图片
  */
 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;
 }