1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-16 03:24:01 +02:00

Centralize dump_headers

This commit is contained in:
Jakub Vrana
2011-02-17 11:43:21 +01:00
parent b1d8bfba36
commit 8ab6fffe74
6 changed files with 22 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ if ($_POST) {
$cookie .= "&$key=" . urlencode($_POST[$key]);
}
cookie("adminer_export", substr($cookie, 1));
$ext = $adminer->dumpHeaders(($TABLE != "" ? $TABLE : DB), (DB == "" || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
$ext = dump_headers(($TABLE != "" ? $TABLE : DB), (DB == "" || count((array) $_POST["tables"] + (array) $_POST["data"]) > 1));
$is_sql = ($_POST["format"] == "sql");
if ($is_sql) {
echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump

View File

@@ -670,7 +670,6 @@ DROP PROCEDURE adminer_alter;
* @return string extension
*/
function dumpHeaders($identifier, $multi_table = false) {
$filename = ($identifier != "" ? friendly_url($identifier) : "adminer");
$output = $_POST["output"];
$ext = ($_POST["format"] == "sql" ? "sql" : ($multi_table ? "tar" : "csv")); // multiple CSV packed to TAR
header("Content-Type: " .
@@ -679,14 +678,10 @@ DROP PROCEDURE adminer_alter;
($ext == "tar" ? "application/x-tar" :
($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
))));
if ($output != "text") {
header("Content-Disposition: attachment; filename=$filename.$ext" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : ""));
}
session_write_close();
if ($_POST["output"] == "bz2") {
if ($output == "bz2") {
ob_start('bzcompress', 1e6);
}
if ($_POST["output"] == "gz") {
if ($output == "gz") {
ob_start('gzencode', 1e6);
}
return $ext;

View File

@@ -754,6 +754,22 @@ function search_tables() {
echo ($found ? "</ul>" : "<p class='message'>" . lang('No tables.')) . "\n";
}
/** Send headers for export
* @param string
* @param bool
* @return string extension
*/
function dump_headers($identifier, $multi_table = false) {
global $adminer;
$return = $adminer->dumpHeaders($identifier, $multi_table);
$output = $_POST["output"];
if ($output != "text") {
header("Content-Disposition: attachment; filename=" . ($identifier != "" ? friendly_url($identifier) : "dump") . ".$return" . ($output != "file" && !ereg('[^0-9a-z]', $output) ? ".$output" : ""));
}
session_write_close();
return $return;
}
/** Print CSV row
* @param array
* @return null

View File

@@ -54,7 +54,7 @@ if ($_POST && !$error) {
}
}
if ($_POST["export"]) {
$adminer->dumpHeaders($TABLE);
dump_headers($TABLE);
$adminer->dumpTable($TABLE, "");
if (!is_array($_POST["check"]) || $unselected === array()) {
$where2 = $where;

View File

@@ -1,6 +1,6 @@
<?php
if (!$error && $_POST["export"]) {
$adminer->dumpHeaders("sql");
dump_headers("sql");
$adminer->dumpTable("", "");
$adminer->dumpData("", "table", $_POST["query"]);
exit;