2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Main export handling code
10 * Get the variables sent or posted to this script and a core script
12 if (!defined('TESTSUITE')) {
14 * If we are sending the export file (as opposed to just displaying it
15 * as text), we have to bypass the usual PMA_Response mechanism
17 if ($_POST['output_format'] == 'sendit') {
18 define('PMA_BYPASS_GET_INSTANCE', 1);
20 require_once 'libraries/common.inc.php';
21 require_once 'libraries/zip.lib.php';
22 require_once 'libraries/plugin_interface.lib.php';
25 * Sets globals from $_POST
27 * - Please keep the parameters in order of their appearance in the form
28 * - Some of these parameters are not used, as the code below directly
29 * verifies from the superglobal $_POST or $_REQUEST
49 'htmlword_structure_or_data',
52 'mediawiki_structure_or_data',
55 'pdf_structure_or_data',
56 'odt_structure_or_data',
62 'codegen_structure_or_data',
68 'excel_structure_or_data',
69 'yaml_structure_or_data',
71 'ods_structure_or_data',
73 'json_structure_or_data',
74 'xml_structure_or_data',
75 'xml_export_functions',
76 'xml_export_procedures',
78 'xml_export_triggers',
80 'xml_export_contents',
81 'texytext_structure_or_data',
84 'phparray_structure_or_data',
85 'sql_include_comments',
90 'sql_use_transaction',
93 'sql_structure_or_data',
94 'sql_create_database',
96 'sql_procedure_function',
97 'sql_create_table_statements',
106 'sql_max_query_size',
116 'csv_structure_or_data',
117 // csv_replace should have been here but we use it directly from $_POST
119 'latex_structure_or_data',
120 'latex_structure_caption',
121 'latex_structure_continued_caption',
122 'latex_structure_label',
127 'latex_data_caption',
128 'latex_data_continued_caption',
133 foreach ($post_params as $one_post_param) {
134 if (isset($_POST[$one_post_param])) {
135 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
139 // sanitize this parameter which will be used below in a file inclusion
140 $what = PMA_securePath($what);
142 PMA_Util
::checkParameters(array('what', 'export_type'));
144 // export class instance, not array of properties, as before
145 $export_plugin = PMA_getPlugin(
148 'libraries/plugins/export/',
150 'export_type' => $export_type,
151 'single_table' => isset($single_table)
155 // Backward compatbility
159 if (! isset($export_plugin)) {
160 PMA_fatalError(__('Bad type!'));
164 * valid compression methods
166 $compression_methods = array(
173 * init and variable checking
175 $compression = false;
177 $save_on_server = false;
178 $buffer_needed = false;
180 // Is it a quick or custom export?
181 if ($_REQUEST['quick_or_custom'] == 'quick') {
182 $quick_export = true;
184 $quick_export = false;
187 if ($_REQUEST['output_format'] == 'astext') {
191 if (in_array($_REQUEST['compression'], $compression_methods)) {
192 $compression = $_REQUEST['compression'];
193 $buffer_needed = true;
195 if (($quick_export && ! empty($_REQUEST['quick_export_onserver']))
196 ||
(! $quick_export && ! empty($_REQUEST['onserver']))
199 $onserver = $_REQUEST['quick_export_onserver'];
201 $onserver = $_REQUEST['onserver'];
203 // Will we save dump on server?
204 $save_on_server = ! empty($cfg['SaveDir']) && $onserver;
208 // Does export require to be into file?
209 if ($export_plugin->getProperties()->getForceFile() != null && ! $asfile) {
210 $message = PMA_Message
::error(
211 __('Selected export type has to be saved in file!')
213 if ($export_type == 'server') {
214 $active_page = 'server_export.php';
215 include 'server_export.php';
216 } elseif ($export_type == 'database') {
217 $active_page = 'db_export.php';
218 include 'db_export.php';
220 $active_page = 'tbl_export.php';
221 include 'tbl_export.php';
226 // Generate error url and check for needed variables
227 if ($export_type == 'server') {
228 $err_url = 'server_export.php?' . PMA_URL_getCommon();
229 } elseif ($export_type == 'database' && strlen($db)) {
230 $err_url = 'db_export.php?' . PMA_URL_getCommon($db);
231 // Check if we have something to export
232 if (isset($table_select)) {
233 $tables = $table_select;
237 } elseif ($export_type == 'table' && strlen($db) && strlen($table)) {
238 $err_url = 'tbl_export.php?' . PMA_URL_getCommon($db, $table);
240 PMA_fatalError(__('Bad parameters!'));
244 * Increase time limit for script execution and initializes some variables
246 @set_time_limit
($cfg['ExecTimeLimit']);
247 if (! empty($cfg['MemoryLimit'])) {
248 @ini_set
('memory_limit', $cfg['MemoryLimit']);
251 // Start with empty buffer
253 $dump_buffer_len = 0;
255 // We send fake headers to avoid browser timeout when buffering
256 $time_start = time();
260 * Detect ob_gzhandler
264 function PMA_isGzHandlerEnabled()
266 return in_array('ob_gzhandler', ob_list_handlers());
270 * Detect whether gzencode is needed; it might not be needed if
271 * the server is already compressing by itself
273 * @return bool Whether gzencode is needed
275 function PMA_gzencodeNeeded()
277 if (@function_exists
('gzencode')
278 && ! @ini_get
('zlib.output_compression')
279 && ! PMA_isGzHandlerEnabled()
288 * Output handler for all exports, if needed buffering, it stores data into
289 * $dump_buffer, otherwise it prints thems out.
291 * @param string $line the insert statement
293 * @return bool Whether output succeeded
295 function PMA_exportOutputHandler($line)
297 global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
299 // Kanji encoding convert feature
300 if ($GLOBALS['output_kanji_conversion']) {
301 $line = PMA_Kanji_strConv(
304 isset($GLOBALS['xkana']) ?
$GLOBALS['xkana'] : ''
307 // If we have to buffer data, we will perform everything at once at the end
308 if ($GLOBALS['buffer_needed']) {
310 $dump_buffer .= $line;
311 if ($GLOBALS['onfly_compression']) {
313 $dump_buffer_len +
= strlen($line);
315 if ($dump_buffer_len > $GLOBALS['memory_limit']) {
316 if ($GLOBALS['output_charset_conversion']) {
317 $dump_buffer = PMA_convertString(
319 $GLOBALS['charset_of_file'],
324 if ($GLOBALS['compression'] == 'bzip2'
325 && @function_exists
('bzcompress')
327 $dump_buffer = bzcompress($dump_buffer);
328 } elseif ($GLOBALS['compression'] == 'gzip'
329 && PMA_gzencodeNeeded()
332 // without the optional parameter level because it bugs
333 $dump_buffer = gzencode($dump_buffer);
335 if ($GLOBALS['save_on_server']) {
336 $write_result = @fwrite
($GLOBALS['file_handle'], $dump_buffer);
337 if (! $write_result ||
($write_result != strlen($dump_buffer))) {
338 $GLOBALS['message'] = PMA_Message
::error(
339 __('Insufficient space to save the file %s.')
341 $GLOBALS['message']->addParam($save_filename);
348 $dump_buffer_len = 0;
352 if ($time_start >= $time_now +
30) {
353 $time_start = $time_now;
354 header('X-pmaPing: Pong');
358 if ($GLOBALS['asfile']) {
359 if ($GLOBALS['output_charset_conversion']) {
360 $line = PMA_convertString(
362 $GLOBALS['charset_of_file'],
366 if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
367 $write_result = @fwrite
($GLOBALS['file_handle'], $line);
368 if (! $write_result ||
($write_result != strlen($line))) {
369 $GLOBALS['message'] = PMA_Message
::error(
370 __('Insufficient space to save the file %s.')
372 $GLOBALS['message']->addParam($save_filename);
376 if ($time_start >= $time_now +
30) {
377 $time_start = $time_now;
378 header('X-pmaPing: Pong');
381 // We export as file - output normally
385 // We export as html - replace special chars
386 echo htmlspecialchars($line);
390 } // end of the 'PMA_exportOutputHandler()' function
392 // Defines the default <CR><LF> format.
393 // For SQL always use \n as MySQL wants this on all platforms.
394 if (!defined('TESTSUITE')) {
395 if ($what == 'sql') {
398 $crlf = PMA_Util
::whichCrlf();
401 $output_kanji_conversion = function_exists('PMA_Kanji_strConv') && $type != 'xls';
403 // Do we need to convert charset?
404 $output_charset_conversion = $asfile
405 && $GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
406 && isset($charset_of_file) && $charset_of_file != 'utf-8'
409 // Use on the fly compression?
410 $onfly_compression = $GLOBALS['cfg']['CompressOnFly']
411 && ($compression == 'gzip' ||
$compression == 'bzip2');
412 if ($onfly_compression) {
413 $memory_limit = trim(@ini_get
('memory_limit'));
415 if (empty($memory_limit)) {
416 $memory_limit = 2 * 1024 * 1024;
419 if (strtolower(substr($memory_limit, -1)) == 'm') {
420 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
421 } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
422 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
423 } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
424 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
426 $memory_limit = (int)$memory_limit;
429 // Some of memory is needed for other things and as threshold.
430 // During export I had allocated (see memory_get_usage function)
431 // approx 1.2MB so this comes from that.
432 if ($memory_limit > 1500000) {
433 $memory_limit -= 1500000;
436 // Some memory is needed for compression, assume 1/3
440 // Generate filename and mime type if needed
442 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
443 if ($export_type == 'server') {
444 if (isset($remember_template)) {
445 $GLOBALS['PMA_Config']->setUserValue(
446 'pma_server_filename_template',
447 'Export/file_template_server',
451 } elseif ($export_type == 'database') {
452 if (isset($remember_template)) {
453 $GLOBALS['PMA_Config']->setUserValue(
454 'pma_db_filename_template',
455 'Export/file_template_database',
460 if (isset($remember_template)) {
461 $GLOBALS['PMA_Config']->setUserValue(
462 'pma_table_filename_template',
463 'Export/file_template_table',
468 $filename = PMA_Util
::expandUserString($filename_template);
469 // remove dots in filename (coming from either the template or already
470 // part of the filename) to avoid a remote code execution vulnerability
471 $filename = PMA_sanitizeFilename($filename, $replaceDots = true);
473 // Grab basic dump extension and mime type
474 // Check if the user already added extension;
475 // get the substring where the extension would be if it was included
476 $extension_start_pos = strlen($filename) - strlen(
477 $export_plugin->getProperties()->getExtension()
479 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
480 $required_extension = "." . $export_plugin->getProperties()->getExtension();
481 if (strtolower($user_extension) != $required_extension) {
482 $filename .= $required_extension;
484 $mime_type = $export_plugin->getProperties()->getMimeType();
486 // If dump is going to be compressed, set correct mime_type and add
487 // compression to extension
488 if ($compression == 'bzip2') {
490 $mime_type = 'application/x-bzip2';
491 } elseif ($compression == 'gzip') {
493 $mime_type = 'application/x-gzip';
494 } elseif ($compression == 'zip') {
496 $mime_type = 'application/zip';
500 // Open file on server if needed
501 if ($save_on_server) {
502 $save_filename = PMA_Util
::userDir($cfg['SaveDir'])
503 . preg_replace('@[/\\\\]@', '_', $filename);
505 if (file_exists($save_filename)
506 && ((! $quick_export && empty($onserverover))
508 && $_REQUEST['quick_export_onserverover'] != 'saveitover'))
510 $message = PMA_Message
::error(
511 __('File %s already exists on server, change filename or check overwrite option.')
513 $message->addParam($save_filename);
515 if (is_file($save_filename) && ! is_writable($save_filename)) {
516 $message = PMA_Message
::error(
517 __('The web server does not have permission to save the file %s.')
519 $message->addParam($save_filename);
521 if (! $file_handle = @fopen
($save_filename, 'w')) {
522 $message = PMA_Message
::error(
523 __('The web server does not have permission to save the file %s.')
525 $message->addParam($save_filename);
529 if (isset($message)) {
530 if ($export_type == 'server') {
531 $active_page = 'server_export.php';
532 include 'server_export.php';
533 } elseif ($export_type == 'database') {
534 $active_page = 'db_export.php';
535 include 'db_export.php';
537 $active_page = 'tbl_export.php';
538 include 'tbl_export.php';
545 * Send headers depending on whether the user chose to download a dump file
548 if (! $save_on_server) {
551 // (avoid rewriting data containing HTML with anchors and forms;
552 // this was reported to happen under Plesk)
553 @ini_set
('url_rewriter.tags', '');
554 $filename = PMA_sanitizeFilename($filename);
556 PMA_downloadHeader($filename, $mime_type);
559 if ($export_type == 'database') {
560 $num_tables = count($tables);
561 if ($num_tables == 0) {
562 $message = PMA_Message
::error(__('No tables found in database.'));
563 $active_page = 'db_export.php';
564 include 'db_export.php';
568 $backup_cfgServer = $cfg['Server'];
569 $cfg['Server'] = $backup_cfgServer;
570 unset($backup_cfgServer);
571 echo "\n" . '<div style="text-align: ' . $cell_align_left . '">' . "\n";
572 //echo ' <pre>' . "\n";
575 * Displays a back button with all the $_REQUEST data in the URL
576 * (store in a variable to also display after the textarea)
578 $back_button = '<p>[ <a href="';
579 if ($export_type == 'server') {
580 $back_button .= 'server_export.php?' . PMA_URL_getCommon();
581 } elseif ($export_type == 'database') {
582 $back_button .= 'db_export.php?' . PMA_URL_getCommon($db);
584 $back_button .= 'tbl_export.php?' . PMA_URL_getCommon($db, $table);
587 // Convert the multiple select elements from an array to a string
588 if ($export_type == 'server' && isset($_REQUEST['db_select'])) {
589 $_REQUEST['db_select'] = implode(",", $_REQUEST['db_select']);
590 } elseif ($export_type == 'database' && isset($_REQUEST['table_select'])) {
591 $_REQUEST['table_select'] = implode(",", $_REQUEST['table_select']);
594 foreach ($_REQUEST as $name => $value) {
595 $back_button .= '&' . urlencode($name) . '=' . urlencode($value);
597 $back_button .= '&repopulate=1">Back</a> ]</p>';
600 echo ' <form name="nofunction">' . "\n"
601 // remove auto-select for now: there is no way to select
602 // only a part of the text; anyway, it should obey
603 // $cfg['TextareaAutoSelect']
604 //. ' <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
605 . ' <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
609 // Fake loop just to allow skip of remain of this code by break, I'd really
610 // need exceptions here :-)
613 // Add possibly some comments to export
614 if (! $export_plugin->exportHeader($db)) {
618 // Will we need relation & co. setup?
619 $do_relation = isset($GLOBALS[$what . '_relation']);
620 $do_comments = isset($GLOBALS[$what . '_include_comments']);
621 $do_mime = isset($GLOBALS[$what . '_mime']);
622 if ($do_relation ||
$do_comments ||
$do_mime) {
623 $cfgRelation = PMA_getRelationsParam();
626 include_once 'libraries/transformations.lib.php';
629 // Include dates in export?
630 $do_dates = isset($GLOBALS[$what . '_dates']);
635 // Gets the number of tables if a dump of a database has been required
636 if ($export_type == 'server') {
637 if (isset($db_select)) {
638 $tmp_select = implode($db_select, '|');
639 $tmp_select = '|' . $tmp_select . '|';
641 // Walk over databases
642 foreach ($GLOBALS['pma']->databases
as $current_db) {
643 if (isset($tmp_select)
644 && strpos(' ' . $tmp_select, '|' . $current_db . '|')
646 if (! $export_plugin->exportDBHeader($current_db)) {
649 if (! $export_plugin->exportDBCreate($current_db)) {
652 if (method_exists($export_plugin, 'exportRoutines')
653 && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
654 && isset($GLOBALS['sql_procedure_function'])
656 $export_plugin->exportRoutines($current_db);
659 $tables = $GLOBALS['dbi']->getTables($current_db);
661 foreach ($tables as $table) {
662 // if this is a view, collect it for later;
663 // views must be exported after the tables
664 $is_view = PMA_Table
::isView($current_db, $table);
668 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
669 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
671 // for a view, export a stand-in definition of the table
672 // to resolve view dependencies
673 if (! $export_plugin->exportStructure(
674 $current_db, $table, $crlf, $err_url,
675 $is_view ?
'stand_in' : 'create_table', $export_type,
676 $do_relation, $do_comments, $do_mime, $do_dates
681 // if this is a view or a merge table, don't export data
682 if (($GLOBALS[$what . '_structure_or_data'] == 'data'
683 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data')
684 && ! ($is_view || PMA_Table
::isMerge($current_db, $table))
686 $local_query = 'SELECT * FROM ' . PMA_Util
::backquote($current_db)
687 . '.' . PMA_Util
::backquote($table);
688 if (! $export_plugin->exportData($current_db, $table, $crlf, $err_url, $local_query)) {
692 // now export the triggers (needs to be done after the data
693 // because triggers can modify already imported tables)
694 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
695 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
697 if (! $export_plugin->exportStructure(
698 $current_db, $table, $crlf, $err_url,
699 'triggers', $export_type,
700 $do_relation, $do_comments, $do_mime, $do_dates
706 foreach ($views as $view) {
707 // no data export for a view
708 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
709 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
711 if (! $export_plugin->exportStructure(
712 $current_db, $view, $crlf, $err_url,
713 'create_view', $export_type,
714 $do_relation, $do_comments, $do_mime, $do_dates
720 if (! $export_plugin->exportDBFooter($current_db)) {
725 } elseif ($export_type == 'database') {
726 if (! $export_plugin->exportDBHeader($db)) {
729 if (! $export_plugin->exportDBCreate($db)) {
733 if (method_exists($export_plugin, 'exportRoutines')
734 && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
735 && isset($GLOBALS['sql_procedure_function'])
737 $export_plugin->exportRoutines($db);
742 // $tables contains the choices from the user (via $table_select)
743 foreach ($tables as $table) {
744 // if this is a view, collect it for later; views must be exported after
746 $is_view = PMA_Table
::isView($db, $table);
750 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
751 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
753 // for a view, export a stand-in definition of the table
754 // to resolve view dependencies
755 if (! $export_plugin->exportStructure(
756 $db, $table, $crlf, $err_url,
757 $is_view ?
'stand_in' : 'create_table', $export_type,
758 $do_relation, $do_comments, $do_mime, $do_dates
763 // if this is a view or a merge table, don't export data
764 if (($GLOBALS[$what . '_structure_or_data'] == 'data'
765 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data')
766 && ! ($is_view || PMA_Table
::isMerge($db, $table))
768 $local_query = 'SELECT * FROM ' . PMA_Util
::backquote($db)
769 . '.' . PMA_Util
::backquote($table);
770 if (! $export_plugin->exportData($db, $table, $crlf, $err_url, $local_query)) {
774 // now export the triggers (needs to be done after the data because
775 // triggers can modify already imported tables)
776 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
777 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
779 if (! $export_plugin->exportStructure(
780 $db, $table, $crlf, $err_url,
781 'triggers', $export_type,
782 $do_relation, $do_comments, $do_mime, $do_dates
788 foreach ($views as $view) {
789 // no data export for a view
790 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
791 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
793 if (! $export_plugin->exportStructure(
794 $db, $view, $crlf, $err_url,
795 'create_view', $export_type,
796 $do_relation, $do_comments, $do_mime, $do_dates
803 if (! $export_plugin->exportDBFooter($db)) {
807 if (! $export_plugin->exportDBHeader($db)) {
810 // We export just one table
811 // $allrows comes from the form when "Dump all rows" has been selected
812 if (isset($allrows) && $allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
813 $add_query = ' LIMIT '
814 . (($limit_from > 0) ?
$limit_from . ', ' : '')
820 $is_view = PMA_Table
::isView($db, $table);
821 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
822 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
824 if (! $export_plugin->exportStructure(
825 $db, $table, $crlf, $err_url,
826 $is_view ?
'create_view' : 'create_table', $export_type,
827 $do_relation, $do_comments, $do_mime, $do_dates
832 // If this is an export of a single view, we have to export data;
833 // for example, a PDF report
834 // if it is a merge table, no data is exported
835 if (($GLOBALS[$what . '_structure_or_data'] == 'data'
836 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data')
837 && ! PMA_Table
::isMerge($db, $table)
839 if (! empty($sql_query)) {
840 // only preg_replace if needed
841 if (! empty($add_query)) {
842 // remove trailing semicolon before adding a LIMIT
843 $sql_query = preg_replace('%;\s*$%', '', $sql_query);
845 $local_query = $sql_query . $add_query;
846 $GLOBALS['dbi']->selectDb($db);
848 $local_query = 'SELECT * FROM ' . PMA_Util
::backquote($db)
849 . '.' . PMA_Util
::backquote($table) . $add_query;
851 if (! $export_plugin->exportData($db, $table, $crlf, $err_url, $local_query)) {
855 // now export the triggers (needs to be done after the data because
856 // triggers can modify already imported tables)
857 if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
858 ||
$GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
860 if (! $export_plugin->exportStructure(
861 $db, $table, $crlf, $err_url,
862 'triggers', $export_type,
863 $do_relation, $do_comments, $do_mime, $do_dates
868 if (! $export_plugin->exportDBFooter($db)) {
872 if (! $export_plugin->exportFooter()) {
879 if ($save_on_server && isset($message)) {
880 if ($export_type == 'server') {
881 $active_page = 'server_export.php';
882 include 'server_export.php';
883 } elseif ($export_type == 'database') {
884 $active_page = 'db_export.php';
885 include 'db_export.php';
887 $active_page = 'tbl_export.php';
888 include 'tbl_export.php';
894 * Send the dump as a file...
896 if (! empty($asfile)) {
897 // Convert the charset if required.
898 if ($output_charset_conversion) {
899 $dump_buffer = PMA_convertString(
901 $GLOBALS['charset_of_file'],
906 // Do the compression
907 // 1. as a zipped file
908 if ($compression == 'zip') {
909 if (@function_exists
('gzcompress')) {
910 $zipfile = new ZipFile();
911 $zipfile->addFile($dump_buffer, substr($filename, 0, -4));
912 $dump_buffer = $zipfile->file();
914 } elseif ($compression == 'bzip2') {
915 // 2. as a bzipped file
916 if (@function_exists
('bzcompress')) {
917 $dump_buffer = bzcompress($dump_buffer);
919 } elseif ($compression == 'gzip' && PMA_gzencodeNeeded()) {
920 // 3. as a gzipped file
921 // without the optional parameter level because it bugs
922 $dump_buffer = gzencode($dump_buffer);
925 /* If we saved on server, we have to close file now */
926 if ($save_on_server) {
927 $write_result = @fwrite
($file_handle, $dump_buffer);
928 fclose($file_handle);
929 if (strlen($dump_buffer) > 0
930 && (! $write_result ||
($write_result != strlen($dump_buffer)))
932 $message = new PMA_Message(
933 __('Insufficient space to save the file %s.'),
938 $message = new PMA_Message(
939 __('Dump has been saved to file %s.'),
940 PMA_Message
::SUCCESS
,
945 if ($export_type == 'server') {
946 $active_page = 'server_export.php';
947 include_once 'server_export.php';
948 } elseif ($export_type == 'database') {
949 $active_page = 'db_export.php';
950 include_once 'db_export.php';
952 $active_page = 'tbl_export.php';
953 include_once 'tbl_export.php';
957 PMA_Response
::getInstance()->disable();
962 * Displays the dump...
964 * Close the html tags and add the footers if dump is displayed on screen
966 echo '</textarea>' . "\n"
971 echo '</div>' . "\n";
974 <script type
="text/javascript">
976 var $body = $
("body");
978 .width($body.width() - 50)
979 .height($body.height() - 100);