当前位置: 首页>>代码示例>>PHP>>正文


PHP Zip::file方法代码示例

本文整理汇总了PHP中Zip::file方法的典型用法代码示例。如果您正苦于以下问题:PHP Zip::file方法的具体用法?PHP Zip::file怎么用?PHP Zip::file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zip的用法示例。


在下文中一共展示了Zip::file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: export

 public static function export($idstr)
 {
     $idArr = is_array($idstr) ? $idstr : explode(",", $idstr);
     if (1 < count($idArr)) {
         $zip = new Zip();
         $exportFileName = Ibos::lang("Form export file pack", "workflow.default", array("{date}" => date("Y-m-d")));
         $zipFileName = FileUtil::getTempPath() . "/" . TIMESTAMP . ".zip";
         foreach ($idArr as $id) {
             $form = self::handleExportSingleForm($id);
             $zip->addFile($form["content"], sprintf("%s.html", ConvertUtil::iIconv($form["title"], CHARSET, "gbk")));
         }
         $fp = fopen($zipFileName, "w");
         if (@fwrite($fp, $zip->file()) !== false) {
             header("Cache-control: private");
             header("Content-type: application/octet-stream");
             header("Accept-Ranges: bytes");
             header("Content-Length: " . sprintf("%u", FileUtil::fileSize($zipFileName)));
             header("Content-Disposition: attachment; filename=" . $exportFileName . ".zip");
             readfile($zipFileName);
             exit;
         }
     } else {
         $id = implode(",", $idArr);
         $form = self::handleExportSingleForm($id);
         ob_end_clean();
         header("Cache-control: private");
         header("Content-type: text/plain");
         header("Accept-Ranges: bytes");
         header("Accept-Length: " . strlen($form["content"]));
         header("Content-Disposition: attachment; filename=" . $form["title"] . ".html");
         echo $form["content"];
     }
 }
开发者ID:AxelPanda,项目名称:ibos,代码行数:33,代码来源:WfFormUtil.php

示例2: databaseBackup

 public static function databaseBackup()
 {
     $config = Ibos::app()->setting->toArray();
     $command = Ibos::app()->db->createCommand("SET SQL_QUOTE_SHOW_CREATE=0");
     $command->execute();
     $fileName = EnvUtil::getRequest("filename");
     $hasDangerFileName = preg_match("/(\\.)(exe|jsp|asp|aspx|cgi|fcgi|pl)(\\.|\$)/i", $fileName);
     if (!$fileName || (bool) $hasDangerFileName) {
         return array("type" => "error", "msg" => Ibos::lang("Database export filename invalid", "dashboard.default"));
     }
     $tablePrefix = $config["config"]["db"]["tableprefix"];
     $dbCharset = $config["config"]["db"]["charset"];
     $type = EnvUtil::getRequest("backuptype");
     if ($type == "all") {
         $tableList = self::getTablelist($tablePrefix);
         $tables = self::arrayKeysTo($tableList, "Name");
     } elseif ($type == "custom") {
         $tables = array();
         if (is_null(EnvUtil::getRequest("dbSubmit"))) {
             $tables = Setting::model()->fetchSettingValueByKey("custombackup");
             $tables = unserialize($tables);
         } else {
             $customTables = EnvUtil::getRequest("customtables");
             Setting::model()->updateSettingValueByKey("custombackup", is_null($customTables) ? "" : $customTables);
             $tables =& $customTables;
         }
         if (!is_array($tables) || empty($tables)) {
             return array("type" => "error", "msg" => Ibos::lang("Database export custom invalid", "dashboard.default"));
         }
     }
     $time = date("Y-m-d H:i:s", TIMESTAMP);
     $volume = intval(EnvUtil::getRequest("volume")) + 1;
     $method = EnvUtil::getRequest("method");
     $encode = base64_encode("{$config["timestamp"]}," . VERSION . ",{$type},{$method},{$volume},{$tablePrefix},{$dbCharset}");
     $idString = "# Identify: " . $encode . "\n";
     $sqlCharset = EnvUtil::getRequest("sqlcharset");
     $sqlCompat = EnvUtil::getRequest("sqlcompat");
     $dbVersion = Ibos::app()->db->getServerVersion();
     $useZip = EnvUtil::getRequest("usezip");
     $useHex = EnvUtil::getRequest("usehex");
     $extendIns = EnvUtil::getRequest("extendins");
     $sizeLimit = EnvUtil::getRequest("sizelimit");
     $dumpCharset = !empty($sqlCharset) ? $sqlCharset : str_replace("-", "", CHARSET);
     $isNewSqlVersion = "4.1" < $dbVersion && (!is_null($sqlCompat) || $sqlCompat == "MYSQL41");
     $setNames = !empty($sqlCharset) && $isNewSqlVersion ? "SET NAMES '{$dumpCharset}';\n\n" : "";
     if ("4.1" < $dbVersion) {
         if ($sqlCharset) {
             $command->setText("SET NAMES `{$sqlCharset}`")->execute();
         }
         if ($sqlCompat == "MYSQL40") {
             $command->setText("SET SQL_MODE='MYSQL40'")->execute();
         } elseif ($sqlCompat == "MYSQL41") {
             $command->setText("SET SQL_MODE=''")->execute();
         }
     }
     if (!is_dir(self::BACKUP_DIR)) {
         FileUtil::makeDir(self::BACKUP_DIR, 511);
     }
     $backupFileName = self::BACKUP_DIR . "/" . str_replace(array("/", "\\", ".", "'"), "", $fileName);
     if ($method == "multivol") {
         $sqlDump = "";
         $tableId = intval(EnvUtil::getRequest("tableid"));
         $startFrom = intval(EnvUtil::getRequest("startfrom"));
         if (!$tableId && $volume == 1) {
             foreach ($tables as $table) {
                 $sqlDump .= self::getSqlDumpTableStruct($table, $sqlCompat, $sqlCharset, $dumpCharset);
             }
         }
         for (self::$complete = true; strlen($sqlDump) + 500 < $sizeLimit * 1000; $tableId++) {
             $sqlDump .= self::sqlDumpTable($tables[$tableId], $extendIns, $sizeLimit, $useHex, $startFrom, strlen($sqlDump));
             if (self::$complete) {
                 $startFrom = 0;
             }
         }
         $dumpFile = $backupFileName . "-%s.sql";
         !self::$complete && $tableId--;
         if (trim($sqlDump)) {
             $sqlDump = "{$idString}# <?php exit();?>\n# IBOS Multi-Volume Data Dump Vol.{$volume}\n# Version: IBOS {$config["version"]}\n# Time: {$time}\n# Type: {$type}\n# Table Prefix: {$tablePrefix}\n#\n# IBOS Home: http://www.ibos.com.cn\n# Please visit our website for newest infomation about IBOS\n# --------------------------------------------------------\n\n\n{$setNames}" . $sqlDump;
             $dumpFileName = sprintf($dumpFile, $volume);
             @($fp = fopen($dumpFileName, "wb"));
             @flock($fp, 2);
             if (@(!fwrite($fp, $sqlDump))) {
                 @fclose($fp);
                 return array("type" => "error", "msg" => Ibos::lang("Database export file invalid", "dashboard.default"), "url" => "");
             } else {
                 fclose($fp);
                 if ($useZip == 2) {
                     $fp = fopen($dumpFileName, "r");
                     $content = @fread($fp, filesize($dumpFileName));
                     fclose($fp);
                     $zip = new Zip();
                     $zip->addFile($content, basename($dumpFileName));
                     $fp = fopen(sprintf($backupFileName . "-%s.zip", $volume), "w");
                     if (@fwrite($fp, $zip->file()) !== false) {
                         @unlink($dumpFileName);
                     }
                     fclose($fp);
                 }
                 unset($sqlDump);
                 unset($zip);
//.........这里部分代码省略.........
开发者ID:AxelPanda,项目名称:ibos,代码行数:101,代码来源:DatabaseUtil.php


注:本文中的Zip::file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。