/** * Backup file. * * @param string $backupFile * @access public * @return object */ public function backFile($backupFile) { $return = new stdclass(); $return->result = true; $return->error = ''; $this->app->loadClass('pclzip', true); $zip = new pclzip($backupFile); $zip->create($this->app->getAppRoot() . 'www/data/', PCLZIP_OPT_REMOVE_PATH, $this->app->getAppRoot() . 'www/data/'); if ($zip->errorCode != 0) { $return->result = false; $return->error = $zip->errorInfo(); } return $return; }
<?php require "config.php"; if (!isset($_GET['gopath']) || !isset($_SESSION['flist']) || !file_exists("pclzip.php")) { header("Location: ./404.php"); exit; } if (!isset($_GET['getcwd'])) { $getcwd = OPEN; } else { $getcwd = ___realpath(trim($_GET['getcwd'])); } xhtml_head("文件压缩"); if (count($_SESSION['flist']) < 1) { echo "<div class=\"error\">\n"; echo "[<a href=\"./index.php?path=" . urlencode($getcwd) . "\">返回</a>]抱歉,文件清单为空!\n"; echo "</div>\n"; } else { require "pclzip.php"; $pkzip = new pclzip($gopath = trim($_GET['gopath'])); echo "[<a href=\"./index.php?path=" . urlencode($getcwd) . "\">目录</a>]\n"; if ($pkzip->create($_SESSION['flist'], PCLZIP_OPT_REMOVE_PATH, dirname($gopath))) { echo "文件 " . ___basename($gopath) . " 创建成功!"; } else { echo "文件 " . ___basename($gopath) . " 无法建立!"; } } xhtml_footer();
/* Backup database. */ $dbRawFile = "db." . date('Ymd') . ".sql"; $password = $config->db->password ? "-p{$config->db->password}" : ' '; $command = "\"{$mysqldump}\" -u{$config->db->user} {$password} -P {$config->db->port} {$config->db->name} > {$dbRawFile}"; echo "Backup command: " . $command . "\n"; echo "Backuping database,"; system($command, $return); if ($return == 0) { $dbZipFile = $destDir . "/" . str_replace("sql", "zip", $dbRawFile); $archive = new pclzip($dbZipFile); if ($archive->create($dbRawFile)) { unlink($dbRawFile); echo " successfully saved to {$dbZipFile}\n"; } else { die("Error : " . $archive->errorInfo(true)); } } else { echo "Failed to backup database!\n"; } /* Backup the attachments. */ chdir(dirname(dirname(dirname(__FILE__))) . "/www"); if (!is_dir('data/upload')) { die(" No files needed backup.\n"); } echo "Backuping files,"; $attachFile = $destDir . "/" . "file." . date('Ymd', time()) . ".zip"; $archive = new pclzip($attachFile); if ($archive->create("data/upload", PCLZIP_OPT_REMOVE_PATH, "data")) { die(" successfully saved to {$attachFile}\n"); } die("Error : " . $archive->errorInfo(true));
/** * Down notify. * * @access public * @return void */ public function downNotify() { $notifyDir = $this->app->getBasePath() . 'www/data/notify/'; $packageFile = $notifyDir . 'notify.zip'; $tmpDir = $notifyDir . 'notify'; $loginFile = $tmpDir . '/notify/logininfo'; $this->app->loadClass('pclzip', true); $sourceZip = new pclzip($packageFile); $files = $sourceZip->extract(PCLZIP_OPT_PATH, $notifyDir); if ($files == 0) { die("Error : " . $sourceZip->errorInfo(true)); } $loginInfo = new stdclass(); $loginInfo->account = $this->app->user->account; $loginInfo->password = $this->app->user->password; $loginInfo->zentaoRoot = common::getSysURL() . $this->config->webRoot; $loginInfo = json_encode($loginInfo); file_put_contents($loginFile, $loginInfo); unlink($packageFile); $newZip = new pclzip($packageFile); if ($newZip->create($tmpDir, PCLZIP_OPT_REMOVE_PATH, $notifyDir)) { $this->zfile = $this->app->loadClass('zfile'); $this->zfile->removeDir($tmpDir); } $this->fetch('file', 'sendDownHeader', array('fileName' => 'notify.zip', 'zip', file_get_contents($packageFile))); }
<body> <div class="big_board"><div class="board_title">爱特文管-路径信息</div></div> HTML; echo '<a href="index.php?path=' . $_GET['path'] . '">' . _decode($_GET['path']) . '</a>'; if (count($_SESSION['path']) <= 0) { echo <<<HTML <div class="big_board"><div class="board_title">爱特文管-系统警告</div></div> Hello,待处理文件为空! HTML; } elseif (preg_match('/^([a-zA-Z0-9_\\-\\.\\x{4e00}-\\x{9fa5}]+)([zip])$/iu', $_REQUEST['pkname']) == false) { echo '<div class="big_board"><div class="board_title">爱特文管-系统警告</div></div>Hello,存档名称不规范喔!'; } else { $i = 0; while ($i < count($_SESSION['path'])) { $_SESSION['path']['decode'][] = _decode($_SESSION['path'][$i]); $i++; } $pk = new pclzip(_decode($_GET['path']) . '/' . $_REQUEST['pkname']); echo <<<HTML <div class="big_board"><div class="board_title">压缩数据-压缩结果</div></div> HTML; if ($pk->create($_SESSION['path']['decode'], PCLZIP_OPT_REMOVE_PATH, _decode($_GET['path'])) == true) { echo 'Hello,压缩包 ' . $_REQUEST['pkname'] . ' 生成成功!'; } else { echo 'Hello,压缩包 ' . $_REQUEST['pkname'] . ' 生成失败!'; } } echo <<<HTML <div class="big_board"><div class="board_title">By:Admin@Aite.Me</div></div> HTML; unset($_SESSION['path']);
/** * Export data to Excel. This is main function. * * @param object $data * @param string $savePath , define the path to save xlsx file * @access public * @return void */ public function export($data, $savePath = '') { $this->init($data); $this->setDocProps(); $this->excelKey = array(); for ($i = 0; $i < count($this->fieldsKey); $i++) { $field = $this->fieldsKey[$i]; $this->excelKey[$field] = $this->setExcelField($i); if (in_array($field, $this->config->excel->centerFields)) { $this->styleSetting['center'][$this->excelKey[$field]] = 1; } if (strpos($field, 'Date') !== false || in_array($field, $this->config->excel->dateField)) { $this->styleSetting['date'][$this->excelKey[$field]] = 1; } } /* Show header data. */ $this->sheet1SheetData = '<row r="1" spans="1:%colspan%" ht="20" customHeight="1">'; foreach ($this->fields as $key => $field) { $this->sheet1SheetData .= $this->setCellValue($this->excelKey[$key], '1', $field, !isset($this->rawExcelData->nocolor)); } $this->sheet1SheetData .= '</row>'; /* Write system data in excel.*/ $this->writeSysData(); $i = 1; $excelData = array(); foreach ($this->rows as $num => $row) { $i++; $columnData = array(); $this->sheet1SheetData .= '<row r="' . $i . '" spans="1:%colspan%" ht="20" customHeight="1">'; foreach ($this->excelKey as $key => $letter) { $value = isset($row[$key]) ? $row[$key] : ''; /* Merge Cells.*/ if (isset($this->rawExcelData->rowspan[$num]) and strpos($this->rawExcelData->rowspan[$num]['rows'], ",{$key},") !== false) { $this->mergeCells($letter . $i, $letter . ($i + $this->rawExcelData->rowspan[$num]['num'] - 1)); } if (isset($this->rawExcelData->colspan[$num]) and strpos($this->rawExcelData->colspan[$num]['cols'], ",{$key},") !== false) { $this->mergeCells($letter . $i, chr(ord($letter) + $this->rawExcelData->colspan[$num]['num'] - 1) . $i); } /* Wipe off html tags. Use to export html message like company->selfDesc via js::kindeditor */ if (isset($this->config->excel->editor[$this->rawExcelData->kind]) and in_array($key, $this->config->excel->editor[$this->rawExcelData->kind])) { $value = $this->file->excludeHtml($value); } if (isset($value[1])) { $value = $value[1] == ':' ? $substr($value, 2) : $value; } $this->sheet1SheetData .= $this->setCellValue($letter, $i, $value, !isset($this->rawExcelData->nocolor)); /* Build excel list.*/ if (isset($this->rawExcelData->listStyle) and in_array($key, $this->rawExcelData->listStyle)) { $this->buildList($key, $i); } } $this->sheet1SheetData .= '</row>'; } $this->sheet1Params['colspan'] = count($this->excelKey) - 1; $this->setStyle($i); if (!empty($this->sheet1Params['cols'])) { $this->sheet1Params['cols'] = '<cols>' . $this->sheet1Params['cols'] . '</cols>'; } if (!empty($this->sheet1Params['mergeCells'])) { $this->sheet1Params['mergeCells'] = '<mergeCells count="' . $this->counts['mergeCells'] . '">' . $this->sheet1Params['mergeCells'] . '</mergeCells>'; } if (!empty($this->sheet1Params['dataValidations'])) { $this->sheet1Params['dataValidations'] = '<dataValidations count="' . $this->counts['dataValidations'] . '">' . $this->sheet1Params['dataValidations'] . '</dataValidations>'; } if (!empty($this->sheet1Params['hyperlinks'])) { $this->sheet1Params['hyperlinks'] = '<hyperlinks>' . $this->sheet1Params['hyperlinks'] . '</hyperlinks>'; } /* Save sheet1*/ $sheet1 = file_get_contents($this->exportPath . 'xl/worksheets/sheet1.xml'); $sheet1 = str_replace(array('%area%', '%xSplit%', '%topLeftCell%', '%cols%', '%sheetData%', '%mergeCells%', '%dataValidations%', '%hyperlinks%', '%colspan%'), array($this->sheet1Params['area'], $this->sheet1Params['xSplit'], $this->sheet1Params['topLeftCell'], $this->sheet1Params['cols'], $this->sheet1SheetData, $this->sheet1Params['mergeCells'], $this->sheet1Params['dataValidations'], $this->sheet1Params['hyperlinks'], $this->sheet1Params['colspan']), $sheet1); file_put_contents($this->exportPath . 'xl/worksheets/sheet1.xml', $sheet1); /* Save sharedStrings file. */ $this->sharedStrings .= '</sst>'; $this->sharedStrings = str_replace('%count%', $this->record, $this->sharedStrings); file_put_contents($this->exportPath . 'xl/sharedStrings.xml', $this->sharedStrings); /* Save link message. */ if ($this->rels) { $this->rels = '<?xml version="1.0" encoding="UTF-8" standalone="yes"? ><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' . $this->rels . '</Relationships>'; if (!is_dir($this->exportPath . 'xl/worksheets/_rels/')) { mkdir($this->exportPath . 'xl/worksheets/_rels/'); } file_put_contents($this->exportPath . 'xl/worksheets/_rels/sheet1.xml.rels', $this->rels); } /* urlencode the filename for ie. */ $fileName = $this->rawExcelData->fileName . '.xlsx'; /* Zip to xlsx. */ helper::cd($this->exportPath); $files = array('[Content_Types].xml', '_rels', 'docProps', 'xl'); $zip = new pclzip($fileName); $zip->create($files); $fileData = file_get_contents($this->exportPath . $fileName); $this->zfile->removeDir($this->exportPath); if ($savePath == '') { $this->sendDownHeader($fileName, 'xlsx', $fileData); } else { file_put_contents($savePath, $fileData); } }