From 5d3c12c5bdce0f15c1a9f4e2d7741b1c1021bc9e Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Mon, 19 Mar 2007 13:43:57 +0000 Subject: [PATCH] bug #1682044 Export file even if file not selected --- ChangeLog | 1 + export.php | 151 +++++++++++++++++++++++++++++------------------------ 2 files changed, 83 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index e4ccb5658..3f1361951 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ $HeadURL$ - bug #1239401 table dot numeric field name - bug #1674972 no export with %afm% - bug #1664212 querywindow loses url encoded characters +- bug #1682044 Export file even if file not selected - [gui] avoid displaying a wide selector in server selection + [core] added PMA_fatalError() and made use of it . [i18n] use generic $strOptions diff --git a/export.php b/export.php index 74eac1cc8..d26a615c0 100644 --- a/export.php +++ b/export.php @@ -1,13 +1,16 @@ = $time_now + 30) { @@ -160,25 +192,9 @@ function PMA_exportOutputHandler($line) echo htmlspecialchars($line); } } - return TRUE; + return true; } // end of the 'PMA_exportOutputHandler()' function -// Will we save dump on server? -$save_on_server = isset($cfg['SaveDir']) && !empty($cfg['SaveDir']) && !empty($onserver); - -// Ensure compressed formats are associated with the download feature -if (empty($asfile)) { - if ($save_on_server) { - $asfile = TRUE; - } elseif (isset($compression) && ($compression == 'zip' | $compression == 'gzip' | $compression == 'bzip')) { - $asfile = TRUE; - } else { - $asfile = FALSE; - } -} else { - $asfile = TRUE; -} - // Defines the default format. For SQL always use \n as MySQL wants this on all platforms. if ($what == 'sql') { $crlf = "\n"; @@ -194,11 +210,8 @@ $output_charset_conversion = $asfile && && isset($charset_of_file) && $charset_of_file != $charset && $type != 'xls'; -// Set whether we will need buffering -$buffer_needed = isset($compression) && ($compression == 'zip' | $compression == 'gzip' | $compression == 'bzip'); - // Use on fly compression? -$onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && isset($compression) && ($compression == 'gzip' | $compression == 'bzip'); +$onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && ($compression == 'gzip' | $compression == 'bzip'); if ($onfly_compression) { $memory_limit = trim(@ini_get('memory_limit')); // 2 MB as default @@ -261,12 +274,12 @@ if ($asfile) { // If dump is going to be compressed, set correct encoding or mime_type and add // compression to extension $content_encoding = ''; - if (isset($compression) && $compression == 'bzip') { + if ($compression == 'bzip') { $filename .= '.bz2'; // browsers don't like this: //$content_encoding = 'x-bzip2'; $mime_type = 'application/x-bzip2'; - } elseif (isset($compression) && $compression == 'gzip') { + } elseif ($compression == 'gzip') { $filename .= '.gz'; // Needed to avoid recompression by server modules like mod_gzip. // It seems necessary to check about zlib.output_compression @@ -275,7 +288,7 @@ if ($asfile) { $content_encoding = 'x-gzip'; $mime_type = 'application/x-gzip'; } - } elseif (isset($compression) && $compression == 'zip') { + } elseif ($compression == 'zip') { $filename .= '.zip'; $mime_type = 'application/zip'; } @@ -287,30 +300,30 @@ if ($save_on_server) { unset($message); if (file_exists($save_filename) && empty($onserverover)) { $message = sprintf($strFileAlreadyExists, htmlspecialchars($save_filename)); - $GLOBALS['show_error_header'] = TRUE; + $GLOBALS['show_error_header'] = true; } else { if (is_file($save_filename) && !is_writable($save_filename)) { $message = sprintf($strNoPermission, htmlspecialchars($save_filename)); - $GLOBALS['show_error_header'] = TRUE; + $GLOBALS['show_error_header'] = true; } else { if (!$file_handle = @fopen($save_filename, 'w')) { $message = sprintf($strNoPermission, htmlspecialchars($save_filename)); - $GLOBALS['show_error_header'] = TRUE; + $GLOBALS['show_error_header'] = true; } } } if (isset($message)) { $js_to_run = 'functions.js'; - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; - require('./server_export.php'); + require './server_export.php'; } elseif ($export_type == 'database') { $active_page = 'db_export.php'; - require('./db_export.php'); + require './db_export.php'; } else { $active_page = 'tbl_export.php'; - require('./tbl_export.php'); + require './tbl_export.php'; } exit(); } @@ -348,14 +361,14 @@ if (!$save_on_server) { if ($num_tables == 0) { $message = $strNoTablesFound; $js_to_run = 'functions.js'; - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; $active_page = 'db_export.php'; - require('./db_export.php'); + require './db_export.php'; exit(); } } $backup_cfgServer = $cfg['Server']; - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; $cfg['Server'] = $backup_cfgServer; unset($backup_cfgServer); echo "\n" . '
' . "\n"; @@ -383,11 +396,11 @@ $do_relation = isset($GLOBALS[$what . '_relation']); $do_comments = isset($GLOBALS[$what . '_comments']); $do_mime = isset($GLOBALS[$what . '_mime']); if ($do_relation || $do_comments || $do_mime) { - require_once('./libraries/relation.lib.php'); + require_once './libraries/relation.lib.php'; $cfgRelation = PMA_getRelationsParam(); } if ($do_mime) { - require_once('./libraries/transformations.lib.php'); + require_once './libraries/transformations.lib.php'; } // Include dates in export? @@ -534,21 +547,21 @@ if (!PMA_exportFooter()) { break; } -} while (FALSE); +} while (false); // End of fake loop if ($save_on_server && isset($message)) { $js_to_run = 'functions.js'; - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; - require('./server_export.php'); + require './server_export.php'; } elseif ($export_type == 'database') { $active_page = 'db_export.php'; - require('./db_export.php'); + require './db_export.php'; } else { $active_page = 'tbl_export.php'; - require('./tbl_export.php'); + require './tbl_export.php'; } exit(); } @@ -564,7 +577,7 @@ if (!empty($asfile)) { // Do the compression // 1. as a gzipped file - if (isset($compression) && $compression == 'zip') { + if ($compression == 'zip') { if (@function_exists('gzcompress')) { $zipfile = new zipfile(); $zipfile -> addFile($dump_buffer, substr($filename, 0, -4)); @@ -572,18 +585,18 @@ if (!empty($asfile)) { } } // 2. as a bzipped file - elseif (isset($compression) && $compression == 'bzip') { + elseif ($compression == 'bzip') { if (@function_exists('bzcompress')) { $dump_buffer = bzcompress($dump_buffer); if ($dump_buffer === -8) { - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; echo sprintf($strBzError, '17300'); - require_once('./libraries/footer.inc.php'); + require_once './libraries/footer.inc.php'; } } } // 3. as a gzipped file - elseif (isset($compression) && $compression == 'gzip') { + elseif ($compression == 'gzip') { if (@function_exists('gzencode')) { // without the optional parameter level because it bug $dump_buffer = gzencode($dump_buffer); @@ -601,16 +614,16 @@ if (!empty($asfile)) { } $js_to_run = 'functions.js'; - require_once('./libraries/header.inc.php'); + require_once './libraries/header.inc.php'; if ($export_type == 'server') { $active_page = 'server_export.php'; - require_once('./server_export.php'); + require_once './server_export.php'; } elseif ($export_type == 'database') { $active_page = 'db_export.php'; - require_once('./db_export.php'); + require_once './db_export.php'; } else { $active_page = 'tbl_export.php'; - require_once('./tbl_export.php'); + require_once './tbl_export.php'; } exit(); } else { @@ -651,6 +664,6 @@ else { //]]>