/** * excel导入信息 */ function import() { if (IS_POST) { $model = M('Member_card'); if ($_FILES['text']['name']) { //$file_dir = $this->upload(); //dump($file_dir);exit; //import("ORG.Net.UploadFile"); import("@.ORG.UploadFile"); $upload = new UploadFile(); $upload->allowExts = array('xls'); $upload->thumbRemoveOrigin = true; //$firstLetter=substr($this->token,0,1); // 设置附件上传目录 $upload->savePath = C('IMG_ROOT') . date('Y') . '/' . date('m') . '/' . date('d') . '/'; // 设置附件上传目录 mk_dir($upload->savePath, 0777); $upload->upload(); $info = $upload->getUploadFileInfo(); if ($info) { $arr_code = $this->daoru($info[0]['savepath'] . $info[0]['savename']); $_POST['file_dir'] = $info[0]['savepath'] . $info[0]['savename']; } else { $this->error($upload->getErrorMsg()); } } else { //$arr_code = explode(',',$_POST['sns']); $arr_code['code'][] = $_POST['code']; $arr_code['psw'][] = $_POST['psw']; } if (!$arr_code) { $this->error('添加失败'); } foreach ($arr_code['code'] as $key => $code) { $add_data['code'] = $code; $count = $model->where($add_data)->count(); if ($count > 0) { continue; } $add_data['psw'] = $arr_code['psw'][$key]; $id = $model->add($add_data); } if ($id) { $this->history($id); $this->success('添加成功!'); } else { $this->error('添加失败!'); } } else { $this->display(); } }
function impUser() { echo "impuser"; die; if (!empty($_FILES)) { import("@.ORG.UploadFile"); $config = array('allowExts' => array('xlsx', 'xls'), 'savePath' => './Public/upload/', 'saveRule' => 'time'); $upload = new \UploadFile($config); if (!$upload->upload()) { $this->error($upload->getErrorMsg()); } else { $info = $upload->getUploadFileInfo(); } vendor("PHPExcel.PHPExcel"); $file_name = $info[0]['savepath'] . $info[0]['savename']; $objReader = PHPExcel_IOFactory::createReader('Excel5'); $objPHPExcel = $objReader->load($file_name, $encode = 'utf-8'); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数 $highestColumn = $sheet->getHighestColumn(); // 取得总列数 for ($i = 3; $i <= $highestRow; $i++) { $data['account'] = $data['truename'] = $objPHPExcel->getActiveSheet()->getCell("B" . $i)->getValue(); $sex = $objPHPExcel->getActiveSheet()->getCell("C" . $i)->getValue(); // $data['res_id'] = $objPHPExcel->getActiveSheet()->getCell("D".$i)->getValue(); $data['class'] = $objPHPExcel->getActiveSheet()->getCell("E" . $i)->getValue(); $data['year'] = $objPHPExcel->getActiveSheet()->getCell("F" . $i)->getValue(); $data['city'] = $objPHPExcel->getActiveSheet()->getCell("G" . $i)->getValue(); $data['company'] = $objPHPExcel->getActiveSheet()->getCell("H" . $i)->getValue(); $data['zhicheng'] = $objPHPExcel->getActiveSheet()->getCell("I" . $i)->getValue(); $data['zhiwu'] = $objPHPExcel->getActiveSheet()->getCell("J" . $i)->getValue(); $data['jibie'] = $objPHPExcel->getActiveSheet()->getCell("K" . $i)->getValue(); $data['honor'] = $objPHPExcel->getActiveSheet()->getCell("L" . $i)->getValue(); $data['tel'] = $objPHPExcel->getActiveSheet()->getCell("M" . $i)->getValue(); $data['qq'] = $objPHPExcel->getActiveSheet()->getCell("N" . $i)->getValue(); $data['email'] = $objPHPExcel->getActiveSheet()->getCell("O" . $i)->getValue(); $data['remark'] = $objPHPExcel->getActiveSheet()->getCell("P" . $i)->getValue(); $data['sex'] = $sex == '男' ? 1 : 0; $data['res_id'] = 1; $data['last_login_time'] = 0; $data['create_time'] = $data['last_login_ip'] = $_SERVER['REMOTE_ADDR']; $data['login_count'] = 0; $data['join'] = 0; $data['avatar'] = ''; $data['password'] = md5('123456'); M('Member')->add($data); } $this->success('导入成功!'); } else { $this->error("请选择上传的文件"); } }
/** * 图片修改 */ public function upablum() { if ($_FILES) { import("ORG.Net.UploadFile"); $upload = new UploadFile(); $is_thumb = 0; $upload->thumb = $is_thumb; $upload->thumbPrefix = '48_,400_'; $upload->thumbMaxWidth = '48,400'; $upload->thumbMaxHeight = '48,400'; //设置上传文件大小 $upload->maxSize = 10241024; //设置上传文件类型 $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'); $upload->saveRule = 'uniqid'; $path = $upload->savePath = C('IMG_ROOT') . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $filepath = date('Y') . '/' . date('m') . '/' . date('d') . '/'; mk_dir($upload->savePath); $upload->upload(); $info = $upload->getUploadFileInfo(); if ($info != "") { foreach ($info as $file) { $key = $file['key']; if ($key == 'up_zp' . $_POST['f_logo']) { $_POST['logo'] = C('IMG_URL') . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $file['savename']; } if ($file['size'] > 307200) { //保留原图并压缩 $ytfile = $path . $file['savename'] . '_yt.jpg'; copy($path . $file['savename'], $ytfile); //300KB $full_blitfilename = $path . $file['savename']; ImageResize($full_blitfilename, 800, 800); } preg_match('/\\d+/i', $key, $matches); $pics['title'][] = $_POST['title' . $matches[0]]; $pics['size'][] = filesize($path . $file['savename']); $pics['filepath'][] = $filepath; $pics['click'][] = rand(0, 10); $pics['savename'][] = $file['savename']; //$pics['title'][] = 'title'.$matches[0]; //匹配出数字和title对应 } } } //dump($pics);exit; if (count($pics['filepath']) > 0) { $model = D('goods'); $vdata['id'] = $_POST['id']; $vo = $model->field('id,member_id')->where($vdata)->find(); $member_id = $vo['member_id']; } $model = D('Pic'); for ($i = 0; $i < count($pics['filepath']); $i++) { $pdata['title'] = $pics['title'][$i]; $pdata['filepath'] = $pics['filepath'][$i]; $pdata['savename'] = $pics['savename'][$i]; $pdata['is_thumb'] = $is_thumb; $pdata['click'] = $pics['click'][$i]; $pdata['size'] = $pics['size'][$i]; $pdata['domain'] = C('IMG_URL'); $pdata['source'] = CONTROLLER_NAME; $pdata['sourceid'] = $_POST['id']; $pdata['sort'] = $i + 1; $pdata['member_id'] = $member_id; //$pdata['webset'] = $vo['webset']; $pdata['user_id'] = $_SESSION[C('USER_AUTH_KEY')]; $pdata['createname'] = $_SESSION['nickname']; $pdata['create_time'] = time(); $picid = $model->add($pdata); } if ($_POST['select_logo']) { $model = D('goods'); $data['id'] = $_POST['id']; $sdata['lit_pic'] = $_POST['select_logo']; $result = $model->where($data)->save($sdata); } if ($result || $picid) { $this->history($_POST['id']); $this->success('修改成功!'); } else { $this->error('修改失败!'); } }
/** * 图片上传处理 * @param [String] $path [保存文件夹名称] * @param [String] $width [缩略图宽度多个用逗号分隔] * @param [String] $height [缩略图高度多个用逗号分隔] * @return [Array] [图片上传信息] */ private function _upload($path, $width, $height) { import('ORG.Net.UploadFile'); //引入ThinkPHP文件上传类 $obj = new \UploadFile(); //实例化上传类 $obj->maxSize = C('UPLOAD_MAX_SIZE'); //图片最大上传大小 $obj->savePath = C('UPLOAD_PATH') . $path . '/'; //图片保存路径 $obj->saveRule = 'uniqid'; //保存文件名 $obj->uploadReplace = true; //覆盖同名文件 $obj->allowExts = C('UPLOAD_EXTS'); //允许上传文件的后缀名 $obj->thumb = true; //生成缩略图 $obj->thumbMaxWidth = $width; //缩略图宽度 $obj->thumbMaxHeight = $height; //缩略图高度 $obj->thumbPrefix = 'max_,medium_,mini_'; //缩略图后缀名 $obj->thumbPath = $obj->savePath . date('Y_m') . '/'; //缩略图保存图径 $obj->thumbRemoveOrigin = true; //删除原图 $obj->autoSub = true; //使用子目录保存文件 $obj->subType = 'date'; //使用日期为子目录名称 $obj->dateFormat = 'Y_m'; //使用 年_月 形式 if (!$obj->upload()) { return array('status' => 0, 'msg' => $obj->getErrorMsg()); } else { $info = $obj->getUploadFileInfo(); $pic = explode('/', $info[0]['savename']); return array('status' => 1, 'path' => array('max' => $pic[0] . '/max_' . $pic[1], 'medium' => $pic[0] . '/medium_' . $pic[1], 'mini' => $pic[0] . '/mini_' . $pic[1])); } }
/** * 上传图片 */ protected function upload($options){ import('@.ORG.UploadFile'); //导入上传类 $upload = new \UploadFile(); //设置上传文件大小 $upload->maxSize = 3292200; //设置上传文件类型 $upload->allowExts = explode(',', 'jpg,gif,png,jpeg'); //设置附件上传目录 $upload->savePath = $options['savePath'] ? $options['savePath'] : C('IMG_ROOT'); //设置需要生成缩略图,仅对图像文件有效 $upload->thumb = $options['thumb'] ? $options['thumb'] : C('thumb'); // 设置引用图片类库包路径 $upload->imageClassPath = '@.ORG.Image'; //设置需要生成缩略图的文件后缀 $upload->thumbPrefix = $options['thumbPrefix'] ? $options['thumbPrefix'] : C('thumbPrefix'); //生产2张缩略图 //设置缩略图最大宽度 $upload->thumbMaxWidth = $options['thumbMaxWidth'] ? $options['thumbMaxWidth'] : C('thumbMaxWidth'); //设置缩略图最大高度 $upload->thumbMaxHeight = $options['thumbMaxHeight'] ? $options['thumbMaxHeight'] : C('thumbMaxHeight'); //设置上传文件规则 $upload->saveRule = 'uniqid'; //删除原图 $upload->thumbRemoveOrigin = true; if (!$upload->upload()) { //捕获上传异常 $this->error($upload->getErrorMsg()); } else { //取得成功上传的文件信息 $info = $upload->getUploadFileInfo(); //dump($info);exit; if($info!=""){ $result['data'] = $info; foreach($info as $file){ $key = $file['key']; $_POST[$key] = C('IMG_URL').$file['savename']; $result['url'][$key] = $_POST[$key]; $result['info'][$key] = $file; } }else{ $result = ''; } } return $result; }