/** * 增加新的记录 * @param array $postArr * @param string $file 上传的文件 */ public function importExcel($postArr, $file) { $serverList = $this->_getCheckServerList(); $operatorMark = $this->_getOperatorMark(); $operatorId = $postArr['operator_id']; $this->_utilRbac = $this->_getGlobalData('Util_Rbac', 'object'); $userClass = $this->_utilRbac->getUserClass(); $this->_loadCore('Help_Excel'); $this->_loadCore('Help_FileUpload'); if (!$file) { return array('msg' => '文件未上传', 'status' => -1, 'href' => 1); } $helpFileUpload = new Help_FileUpload($file, EXCEL_DIR . '/' . date('Ymd'), 1024 * 1024 * 8, array('xls', 'xlsx')); $helpFileUpload->singleUpload(); $fileInfo = $helpFileUpload->getSaveInfo(); $helpExcel = new Help_Excel($fileInfo['path']); $excelData = $helpExcel->getData(0); array_shift($excelData); $addArr = array(); $num = 0; //记数器,第几行 $retArr = array(); //返回消息 $batchNum = md5(Tools::getRandCode(5) . CURRENT_TIME); $batchNum = substr($batchNum, 0, 16); foreach ($excelData as $value) { $value[0] = strtoupper($value[0]); $num++; if (empty($value[0])) { continue; } $marking = strtolower($operatorMark[$operatorId]) . '|' . trim($value[0]); if (!array_key_exists($marking, $serverList)) { //如果服务器ID不存在将跳过 array_push($retArr, "第 [{$num}] 行服务器ID不存在!"); continue; } $arr = array(); $arr['create_time'] = CURRENT_TIME; $arr['operator_id'] = $operatorId ? $operatorId : array_search(strtolower(trim($value[2])), $operatorMark); //运营商ID $arr['server_id'] = $serverList[$marking]; //serverid $arr['user_id'] = $userClass['_id']; $arr['batch_num'] = $batchNum; $arr['player_id'] = trim($value[1]); array_push($addArr, $arr); } if (count($retArr)) { //如果有错误信息 return array('msg' => implode('<br />', $retArr), 'status' => -1, 'href' => 1); } if ($this->adds($addArr)) { $dataList = $this->select("select * from {$this->tName()} where batch_num='{$batchNum}'"); return array('msg' => '上传文件成功', 'status' => 1, 'href' => 1, 'data' => $dataList); } else { return array('msg' => '失败', 'status' => -1, 'href' => 1); } }
private function _upload() { $this->_loadCore('Help_FileUpload'); $uploadPath = UPDATE_DIR . '/zlsg/' . date('Ymd', CURRENT_TIME); $helpFileUpload = new Help_FileUpload($_FILES['Excel'], $uploadPath); $helpFileUpload->setBaseUrl(__ROOT__ . '/Upload/zlsg/' . date('Ymd', CURRENT_TIME)); $helpFileUpload->singleUpload(); return $helpFileUpload->getSaveInfo(); }
/** * 文件上传 */ private function _upload() { $this->_loadCore('Help_FileUpload'); $uploadPath = UPDATE_DIR . '/Player/' . date('Ymd', CURRENT_TIME); $helpFileUpload = new Help_FileUpload($_FILES['image'], $uploadPath); $helpFileUpload->setBaseUrl(__ROOT__ . '/Upload/Player/' . date('Ymd', CURRENT_TIME)); if (is_array($_FILES['image']['name'])) { $helpFileUpload->upload(); return $helpFileUpload->getSaveInfo(); } else { $helpFileUpload->singleUpload(); return array($helpFileUpload->getSaveInfo()); } }
/** * 用exlce文件中的用户账号,查询用户 */ public function actionUserQueryByExcel() { $this->_createServerList(); if ($this->_isPost()) { if (!strtotime($_POST['StartTime']) || !strtotime($_POST['EndTime'])) { $this->_utilMsg->showMsg(Tools::getLang('PLZ_INSERT_CORRECT_TIME', 'Common'), -1); } $file = $_FILES['upload']; $postData = array(); if ($file['error'] == 0) { $this->_loadCore('Help_FileUpload'); $helpFileUpload = new Help_FileUpload($file, EXCEL_DIR . '/' . date('Ymd'), 1024 * 1024 * 8, array('xls', 'xlsx')); $helpFileUpload->singleUpload(); $fileInfo = $helpFileUpload->getSaveInfo(); $this->_loadCore('Help_Excel'); $helpExcel = new Help_Excel($fileInfo['path']); $excelData = $helpExcel->getData(0); array_shift($excelData); foreach ($excelData as $sub) { $postData[$sub[0]] = $sub[0]; } } $postData = implode(',', $postData); $this->_utilFRGInterface = $this->_getGlobalData('Util_FRGInterface', 'object'); $this->_utilFRGInterface->setServerUrl($_REQUEST['server_id']); $this->_utilFRGInterface->setGet(array('c' => 'UserData', 'a' => 'ExportUser')); $this->_utilFRGInterface->setPost(array('StartTime' => $_POST['StartTime'], 'EndTime' => $_POST['EndTime'], 'UserNames' => $postData)); $data = $this->_utilFRGInterface->callInterface(); if ($data['msgno'] != 0) { $this->_utilMsg->showMsg($data['message'], -1); } Tools::import('Util_ExportExcel'); $this->_utilExportExcel = new Util_ExportExcel($_GET['server_id'] . '_' . CURRENT_TIME, 'Excel/UserInfo', $data['data']); $this->_utilExportExcel->outPutExcel(); return; } $operatorList = $this->_getGlobalData('operator_list'); $operatorList = Model::getTtwoArrConvertOneArr($operatorList, 'Id', 'operator_name'); $this->_view->assign('operatorList', $operatorList); $this->_utilMsg->createNavBar(); $this->_view->display(); }
/** * 文件上传 */ private function _upload() { $this->_loadCore('Help_FileUpload'); $uploadPath = UPDATE_DIR . '/Player/' . date('Ymd', CURRENT_TIME); $helpFileUpload = new Help_FileUpload($_FILES['image'], $uploadPath); $helpFileUpload->setBaseUrl(__ROOT__ . '/Upload/Player/' . date('Ymd', CURRENT_TIME)); $helpFileUpload->singleUpload(); // Tools::dump($helpFileUpload->getSaveInfo()); return $helpFileUpload->getSaveInfo(); }
/** * 文件上传 * @param FILES $files上传的文件 * @param int $maxFile最大上传的文件数 */ private function _newsFileUpload($files = null, $maxFile = 5, $maxSize = 2097152) { if (empty($files)) { $files = $_FILES['files']; } $this->_loadCore('Help_FileUpload'); $Ymd = date('Ymd', CURRENT_TIME); $uploadPath = UPDATE_DIR . '/' . self::NEWS_PATH . '/' . $Ymd; $helpFileUpload = new Help_FileUpload($files, $uploadPath, $maxSize, $this->_allowTypes); //2M文件限制 $helpFileUpload->setBaseUrl(__ROOT__ . '/Upload/' . self::NEWS_PATH . '/' . date('Ymd', CURRENT_TIME)); $returnData = array('uploadData' => array(), 'errorInfo' => ''); if (is_array($files['name'])) { $helpFileUpload->upload($maxFile); $uploadInfo = $helpFileUpload->getSaveInfo(); } else { $helpFileUpload->singleUpload(); $uploadInfo = array($helpFileUpload->getSaveInfo()); } if ($uploadInfo) { foreach ($uploadInfo as $sub) { if (isset($sub['name'])) { $returnData['uploadData'][] = array('name' => $sub['name'], 'type' => $sub['type'], 'size' => $this->_getSizeString($sub['size']), 'path' => "{$Ymd}/{$sub['saveas']}"); } else { $returnData['errorInfo'] .= $sub['web_path'] . '<br>'; } } } return $returnData; }