adminerevo/plugins/dump-zip.php

46 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2011-02-17 10:47:36 +00:00
<?php
/** Dump to ZIP format
2015-09-08 16:23:25 +00:00
* @link https://www.adminer.org/plugins/#use
2011-02-17 10:47:36 +00:00
* @uses ZipArchive, tempnam("")
2017-02-27 12:43:33 +00:00
* @author Jakub Vrana, https://www.vrana.cz/
2018-01-14 10:03:54 +00:00
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
2011-02-17 10:47:36 +00:00
*/
class AdminerDumpZip {
2011-08-11 15:06:42 +00:00
/** @access protected */
2012-06-29 21:09:44 +00:00
var $filename, $data;
2011-02-17 10:47:36 +00:00
function dumpOutput() {
if (!class_exists('ZipArchive')) {
return array();
}
return array('zip' => 'ZIP');
}
2011-02-17 10:47:36 +00:00
function _zip($string, $state) {
2013-04-04 16:44:48 +00:00
// ZIP can be created without temporary file by gzcompress - see PEAR File_Archive
2012-06-29 21:09:44 +00:00
$this->data .= $string;
2011-02-17 10:47:36 +00:00
if ($state & PHP_OUTPUT_HANDLER_END) {
$zip = new ZipArchive;
$zipFile = tempnam("", "zip");
$zip->open($zipFile, ZipArchive::OVERWRITE); // php://output is not supported
2012-06-29 21:09:44 +00:00
$zip->addFromString($this->filename, $this->data);
2011-02-17 10:47:36 +00:00
$zip->close();
$return = file_get_contents($zipFile);
unlink($zipFile);
return $return;
}
return "";
}
2011-02-17 10:47:36 +00:00
function dumpHeaders($identifier, $multi_table = false) {
if ($_POST["output"] == "zip") {
$this->filename = "$identifier." . ($multi_table && preg_match("~[ct]sv~", $_POST["format"]) ? "tar" : $_POST["format"]);
2011-02-17 10:47:36 +00:00
header("Content-Type: application/zip");
2012-06-29 21:09:44 +00:00
ob_start(array($this, '_zip'));
2011-02-17 10:47:36 +00:00
}
}
}