3.4.6 release
[phpmyadmin/alexukf.git] / export.php
blobfb8805a4e1c552582afdd5747eb3cf1b1f9f0784
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @todo too much die here, or?
5 * @package phpMyAdmin
6 */
8 /**
9 * Get the variables sent or posted to this script and a core script
11 require_once './libraries/common.inc.php';
12 require_once './libraries/zip.lib.php';
13 require_once './libraries/plugin_interface.lib.php';
15 PMA_checkParameters(array('what', 'export_type'));
17 // Scan plugins
18 $export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
20 // Backward compatbility
21 $type = $what;
23 // Check export type
24 if (!isset($export_list[$type])) {
25 die('Bad type!');
28 /**
29 * valid compression methods
31 $compression_methods = array(
32 'zip',
33 'gzip',
34 'bzip',
37 /**
38 * init and variable checking
40 $compression = false;
41 $onserver = false;
42 $save_on_server = false;
43 $buffer_needed = false;
45 // Is it a quick or custom export?
46 if($_REQUEST['quick_or_custom'] == 'quick') {
47 $quick_export = true;
48 } else {
49 $quick_export = false;
52 if ($_REQUEST['output_format'] == 'astext') {
53 $asfile = false;
54 } else {
55 $asfile = true;
56 if (in_array($_REQUEST['compression'], $compression_methods)) {
57 $compression = $_REQUEST['compression'];
58 $buffer_needed = true;
60 if (($quick_export && !empty($_REQUEST['quick_export_onserver'])) || (!$quick_export && !empty($_REQUEST['onserver']))) {
61 if($quick_export) {
62 $onserver = $_REQUEST['quick_export_onserver'];
63 } else {
64 $onserver = $_REQUEST['onserver'];
66 // Will we save dump on server?
67 $save_on_server = ! empty($cfg['SaveDir']) && $onserver;
71 // Does export require to be into file?
72 if (isset($export_list[$type]['force_file']) && ! $asfile) {
73 $message = PMA_Message::error(__('Selected export type has to be saved in file!'));
74 require_once './libraries/header.inc.php';
75 if ($export_type == 'server') {
76 $active_page = 'server_export.php';
77 require './server_export.php';
78 } elseif ($export_type == 'database') {
79 $active_page = 'db_export.php';
80 require './db_export.php';
81 } else {
82 $active_page = 'tbl_export.php';
83 require './tbl_export.php';
85 exit();
88 // Generate error url and check for needed variables
89 if ($export_type == 'server') {
90 $err_url = 'server_export.php?' . PMA_generate_common_url();
91 } elseif ($export_type == 'database' && strlen($db)) {
92 $err_url = 'db_export.php?' . PMA_generate_common_url($db);
93 // Check if we have something to export
94 if (isset($table_select)) {
95 $tables = $table_select;
96 } else {
97 $tables = array();
99 } elseif ($export_type == 'table' && strlen($db) && strlen($table)) {
100 $err_url = 'tbl_export.php?' . PMA_generate_common_url($db, $table);
101 } else {
102 die('Bad parameters!');
105 // Get the functions specific to the export type
106 require './libraries/export/' . PMA_securePath($type) . '.php';
109 * Increase time limit for script execution and initializes some variables
111 @set_time_limit($cfg['ExecTimeLimit']);
112 if (!empty($cfg['MemoryLimit'])) {
113 @ini_set('memory_limit', $cfg['MemoryLimit']);
116 // Start with empty buffer
117 $dump_buffer = '';
118 $dump_buffer_len = 0;
120 // We send fake headers to avoid browser timeout when buffering
121 $time_start = time();
125 * Output handler for all exports, if needed buffering, it stores data into
126 * $dump_buffer, otherwise it prints thems out.
128 * @param string the insert statement
130 * @return bool Whether output suceeded
132 function PMA_exportOutputHandler($line)
134 global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
136 // Kanji encoding convert feature
137 if ($GLOBALS['output_kanji_conversion']) {
138 $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
140 // If we have to buffer data, we will perform everything at once at the end
141 if ($GLOBALS['buffer_needed']) {
143 $dump_buffer .= $line;
144 if ($GLOBALS['onfly_compression']) {
146 $dump_buffer_len += strlen($line);
148 if ($dump_buffer_len > $GLOBALS['memory_limit']) {
149 if ($GLOBALS['output_charset_conversion']) {
150 $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
152 // as bzipped
153 if ($GLOBALS['compression'] == 'bzip' && @function_exists('bzcompress')) {
154 $dump_buffer = bzcompress($dump_buffer);
156 // as a gzipped file
157 elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) {
158 // without the optional parameter level because it bug
159 $dump_buffer = gzencode($dump_buffer);
161 if ($GLOBALS['save_on_server']) {
162 $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
163 if (!$write_result || ($write_result != strlen($dump_buffer))) {
164 $GLOBALS['message'] = PMA_Message::error(__('Insufficient space to save the file %s.'));
165 $GLOBALS['message']->addParam($save_filename);
166 return false;
168 } else {
169 echo $dump_buffer;
171 $dump_buffer = '';
172 $dump_buffer_len = 0;
174 } else {
175 $time_now = time();
176 if ($time_start >= $time_now + 30) {
177 $time_start = $time_now;
178 header('X-pmaPing: Pong');
179 } // end if
181 } else {
182 if ($GLOBALS['asfile']) {
183 if ($GLOBALS['output_charset_conversion']) {
184 $line = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $line);
186 if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
187 $write_result = @fwrite($GLOBALS['file_handle'], $line);
188 if (!$write_result || ($write_result != strlen($line))) {
189 $GLOBALS['message'] = PMA_Message::error(__('Insufficient space to save the file %s.'));
190 $GLOBALS['message']->addParam($save_filename);
191 return false;
193 $time_now = time();
194 if ($time_start >= $time_now + 30) {
195 $time_start = $time_now;
196 header('X-pmaPing: Pong');
197 } // end if
198 } else {
199 // We export as file - output normally
200 echo $line;
202 } else {
203 // We export as html - replace special chars
204 echo htmlspecialchars($line);
207 return true;
208 } // end of the 'PMA_exportOutputHandler()' function
210 // Defines the default <CR><LF> format. For SQL always use \n as MySQL wants this on all platforms.
211 if ($what == 'sql') {
212 $crlf = "\n";
213 } else {
214 $crlf = PMA_whichCrlf();
217 $output_kanji_conversion = function_exists('PMA_kanji_str_conv') && $type != 'xls';
219 // Do we need to convert charset?
220 $output_charset_conversion = $asfile && $GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
221 && isset($charset_of_file) && $charset_of_file != $charset
222 && $type != 'xls';
224 // Use on the fly compression?
225 $onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && ($compression == 'gzip' || $compression == 'bzip');
226 if ($onfly_compression) {
227 $memory_limit = trim(@ini_get('memory_limit'));
228 // 2 MB as default
229 if (empty($memory_limit)) {
230 $memory_limit = 2 * 1024 * 1024;
233 if (strtolower(substr($memory_limit, -1)) == 'm') {
234 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
235 } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
236 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
237 } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
238 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
239 } else {
240 $memory_limit = (int)$memory_limit;
243 // Some of memory is needed for other thins and as treshold.
244 // Nijel: During export I had allocated (see memory_get_usage function)
245 // approx 1.2MB so this comes from that.
246 if ($memory_limit > 1500000) {
247 $memory_limit -= 1500000;
250 // Some memory is needed for compression, assume 1/3
251 $memory_limit /= 8;
254 // Generate filename and mime type if needed
255 if ($asfile) {
256 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
257 if ($export_type == 'server') {
258 if (isset($remember_template)) {
259 $GLOBALS['PMA_Config']->setUserValue('pma_server_filename_template',
260 'Export/file_template_server', $filename_template);
262 } elseif ($export_type == 'database') {
263 if (isset($remember_template)) {
264 $GLOBALS['PMA_Config']->setUserValue('pma_db_filename_template',
265 'Export/file_template_database', $filename_template);
267 } else {
268 if (isset($remember_template)) {
269 $GLOBALS['PMA_Config']->setUserValue('pma_table_filename_template',
270 'Export/file_template_table', $filename_template);
273 $filename = PMA_expandUserString($filename_template);
274 $filename = PMA_sanitize_filename($filename);
276 // Grab basic dump extension and mime type
277 // Check if the user already added extension; get the substring where the extension would be if it was included
278 $extension_start_pos = strlen($filename) - strlen($export_list[$type]['extension']) - 1;
279 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
280 $required_extension = "." . $export_list[$type]['extension'];
281 if(strtolower($user_extension) != $required_extension) {
282 $filename .= $required_extension;
284 $mime_type = $export_list[$type]['mime_type'];
286 // If dump is going to be compressed, set correct mime_type and add
287 // compression to extension
288 if ($compression == 'bzip') {
289 $filename .= '.bz2';
290 $mime_type = 'application/x-bzip2';
291 } elseif ($compression == 'gzip') {
292 $filename .= '.gz';
293 $mime_type = 'application/x-gzip';
294 } elseif ($compression == 'zip') {
295 $filename .= '.zip';
296 $mime_type = 'application/zip';
300 // Open file on server if needed
301 if ($save_on_server) {
302 $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
303 unset($message);
304 if (file_exists($save_filename) && ((!$quick_export && empty($onserverover)) || ($quick_export && $_REQUEST['quick_export_onserverover'] != 'saveitover'))) {
305 $message = PMA_Message::error(__('File %s already exists on server, change filename or check overwrite option.'));
306 $message->addParam($save_filename);
307 } else {
308 if (is_file($save_filename) && !is_writable($save_filename)) {
309 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
310 $message->addParam($save_filename);
311 } else {
312 if (!$file_handle = @fopen($save_filename, 'w')) {
313 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
314 $message->addParam($save_filename);
318 if (isset($message)) {
319 require_once './libraries/header.inc.php';
320 if ($export_type == 'server') {
321 $active_page = 'server_export.php';
322 require './server_export.php';
323 } elseif ($export_type == 'database') {
324 $active_page = 'db_export.php';
325 require './db_export.php';
326 } else {
327 $active_page = 'tbl_export.php';
328 require './tbl_export.php';
330 exit();
335 * Send headers depending on whether the user chose to download a dump file
336 * or not
338 if (!$save_on_server) {
339 if ($asfile) {
340 // Download
341 // (avoid rewriting data containing HTML with anchors and forms;
342 // this was reported to happen under Plesk)
343 @ini_set('url_rewriter.tags','');
344 $filename = PMA_sanitize_filename($filename);
346 header('Content-Type: ' . $mime_type);
347 header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
348 // Tested behavior of
349 // IE 5.50.4807.2300
350 // IE 6.0.2800.1106 (small glitch, asks twice when I click Open)
351 // IE 6.0.2900.2180
352 // Firefox 1.0.6
353 // in http and https
354 header('Content-Disposition: attachment; filename="' . $filename . '"');
355 if (PMA_USR_BROWSER_AGENT == 'IE') {
356 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
357 header('Pragma: public');
358 } else {
359 header('Pragma: no-cache');
360 // test case: exporting a database into a .gz file with Safari
361 // would produce files not having the current time
362 // (added this header for Safari but should not harm other browsers)
363 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
365 } else {
366 // HTML
367 if ($export_type == 'database') {
368 $num_tables = count($tables);
369 if ($num_tables == 0) {
370 $message = PMA_Message::error(__('No tables found in database.'));
371 require_once './libraries/header.inc.php';
372 $active_page = 'db_export.php';
373 require './db_export.php';
374 exit();
377 $backup_cfgServer = $cfg['Server'];
378 require_once './libraries/header.inc.php';
379 $cfg['Server'] = $backup_cfgServer;
380 unset($backup_cfgServer);
381 echo "\n" . '<div align="' . $cell_align_left . '">' . "\n";
382 //echo ' <pre>' . "\n";
385 * Displays a back button with all the $_REQUEST data in the URL (store in a variable to also display after the textarea)
387 $back_button = '<p>[ <a href="';
388 if ($export_type == 'server') {
389 $back_button .= 'server_export.php?' . PMA_generate_common_url();
390 } elseif ($export_type == 'database') {
391 $back_button .= 'db_export.php?' . PMA_generate_common_url($db);
392 } else {
393 $back_button .= 'tbl_export.php?' . PMA_generate_common_url($db, $table);
396 // Convert the multiple select elements from an array to a string
397 if($export_type == 'server' && isset($_REQUEST['db_select'])) {
398 $_REQUEST['db_select'] = implode(",", $_REQUEST['db_select']);
399 } elseif($export_type == 'database' && isset($_REQUEST['table_select'])) {
400 $_REQUEST['table_select'] = implode(",", $_REQUEST['table_select']);
403 foreach($_REQUEST as $name => $value) {
404 $back_button .= '&' . urlencode($name) . '=' . urlencode($value);
406 $back_button .= '&repopulate=1">Back</a> ]</p>';
408 echo $back_button;
409 echo ' <form name="nofunction">' . "\n"
410 // remove auto-select for now: there is no way to select
411 // only a part of the text; anyway, it should obey
412 // $cfg['TextareaAutoSelect']
413 //. ' <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
414 . ' <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
415 } // end download
418 // Fake loop just to allow skip of remain of this code by break, I'd really
419 // need exceptions here :-)
420 do {
422 // Add possibly some comments to export
423 if (!PMA_exportHeader()) {
424 break;
427 // Will we need relation & co. setup?
428 $do_relation = isset($GLOBALS[$what . '_relation']);
429 $do_comments = isset($GLOBALS[$what . '_include_comments']);
430 $do_mime = isset($GLOBALS[$what . '_mime']);
431 if ($do_relation || $do_comments || $do_mime) {
432 $cfgRelation = PMA_getRelationsParam();
434 if ($do_mime) {
435 require_once './libraries/transformations.lib.php';
438 // Include dates in export?
439 $do_dates = isset($GLOBALS[$what . '_dates']);
442 * Builds the dump
444 // Gets the number of tables if a dump of a database has been required
445 if ($export_type == 'server') {
446 if (isset($db_select)) {
447 $tmp_select = implode($db_select, '|');
448 $tmp_select = '|' . $tmp_select . '|';
450 // Walk over databases
451 foreach ($GLOBALS['pma']->databases as $current_db) {
452 if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
453 || !isset($tmp_select)) {
454 if (!PMA_exportDBHeader($current_db)) {
455 break 2;
457 if (!PMA_exportDBCreate($current_db)) {
458 break 2;
460 if (function_exists('PMA_exportRoutines') && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && isset($GLOBALS['sql_procedure_function'])) {
461 PMA_exportRoutines($current_db);
464 $tables = PMA_DBI_get_tables($current_db);
465 $views = array();
466 foreach ($tables as $table) {
467 // if this is a view, collect it for later; views must be exported
468 // after the tables
469 $is_view = PMA_Table::isView($current_db, $table);
470 if ($is_view) {
471 $views[] = $table;
473 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
474 // for a view, export a stand-in definition of the table
475 // to resolve view dependencies
476 if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
477 break 3;
480 // if this is a view or a merge table, don't export data
481 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !($is_view || PMA_Table::isMerge($current_db, $table))) {
482 $local_query = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table);
483 if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) {
484 break 3;
487 // now export the triggers (needs to be done after the data because
488 // triggers can modify already imported tables)
489 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
490 if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
491 break 2;
495 foreach($views as $view) {
496 // no data export for a view
497 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
498 if (!PMA_exportStructure($current_db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
499 break 3;
503 if (!PMA_exportDBFooter($current_db)) {
504 break 2;
508 } elseif ($export_type == 'database') {
509 if (!PMA_exportDBHeader($db)) {
510 break;
513 if (function_exists('PMA_exportRoutines') && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && isset($GLOBALS['sql_procedure_function'])) {
514 PMA_exportRoutines($db);
517 $i = 0;
518 $views = array();
519 // $tables contains the choices from the user (via $table_select)
520 foreach ($tables as $table) {
521 // if this is a view, collect it for later; views must be exported after
522 // the tables
523 $is_view = PMA_Table::isView($db, $table);
524 if ($is_view) {
525 $views[] = $table;
527 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
528 // for a view, export a stand-in definition of the table
529 // to resolve view dependencies
530 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
531 break 2;
534 // if this is a view or a merge table, don't export data
535 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !($is_view || PMA_Table::isMerge($db, $table))) {
536 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
537 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
538 break 2;
541 // now export the triggers (needs to be done after the data because
542 // triggers can modify already imported tables)
543 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
544 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
545 break 2;
549 foreach ($views as $view) {
550 // no data export for a view
551 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
552 if (!PMA_exportStructure($db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
553 break 2;
558 if (!PMA_exportDBFooter($db)) {
559 break;
561 } else {
562 if (!PMA_exportDBHeader($db)) {
563 break;
565 // We export just one table
566 // $allrows comes from the form when "Dump all rows" has been selected
567 if ($allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
568 $add_query = ' LIMIT '
569 . (($limit_from > 0) ? $limit_from . ', ' : '')
570 . $limit_to;
571 } else {
572 $add_query = '';
575 $is_view = PMA_Table::isView($db, $table);
576 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
577 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) {
578 break;
581 // If this is an export of a single view, we have to export data;
582 // for example, a PDF report
583 // if it is a merge table, no data is exported
584 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && ! PMA_Table::isMerge($db, $table)) {
585 if (!empty($sql_query)) {
586 // only preg_replace if needed
587 if (!empty($add_query)) {
588 // remove trailing semicolon before adding a LIMIT
589 $sql_query = preg_replace('%;\s*$%', '', $sql_query);
591 $local_query = $sql_query . $add_query;
592 PMA_DBI_select_db($db);
593 } else {
594 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query;
596 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
597 break;
600 // now export the triggers (needs to be done after the data because
601 // triggers can modify already imported tables)
602 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
603 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
604 break 2;
607 if (!PMA_exportDBFooter($db)) {
608 break;
611 if (!PMA_exportFooter()) {
612 break;
615 } while (false);
616 // End of fake loop
618 if ($save_on_server && isset($message)) {
619 require_once './libraries/header.inc.php';
620 if ($export_type == 'server') {
621 $active_page = 'server_export.php';
622 require './server_export.php';
623 } elseif ($export_type == 'database') {
624 $active_page = 'db_export.php';
625 require './db_export.php';
626 } else {
627 $active_page = 'tbl_export.php';
628 require './tbl_export.php';
630 exit();
634 * Send the dump as a file...
636 if (!empty($asfile)) {
637 // Convert the charset if required.
638 if ($output_charset_conversion) {
639 $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
642 // Do the compression
643 // 1. as a zipped file
644 if ($compression == 'zip') {
645 if (@function_exists('gzcompress')) {
646 $zipfile = new zipfile();
647 $zipfile -> addFile($dump_buffer, substr($filename, 0, -4));
648 $dump_buffer = $zipfile -> file();
651 // 2. as a bzipped file
652 elseif ($compression == 'bzip') {
653 if (@function_exists('bzcompress')) {
654 $dump_buffer = bzcompress($dump_buffer);
657 // 3. as a gzipped file
658 elseif ($compression == 'gzip') {
659 if (@function_exists('gzencode') && !@ini_get('zlib.output_compression')) {
660 // without the optional parameter level because it bug
661 $dump_buffer = gzencode($dump_buffer);
665 /* If ve saved on server, we have to close file now */
666 if ($save_on_server) {
667 $write_result = @fwrite($file_handle, $dump_buffer);
668 fclose($file_handle);
669 if (strlen($dump_buffer) !=0 && (!$write_result || ($write_result != strlen($dump_buffer)))) {
670 $message = new PMA_Message(__('Insufficient space to save the file %s.'), PMA_Message::ERROR, $save_filename);
671 } else {
672 $message = new PMA_Message(__('Dump has been saved to file %s.'), PMA_Message::SUCCESS, $save_filename);
675 require_once './libraries/header.inc.php';
676 if ($export_type == 'server') {
677 $active_page = 'server_export.php';
678 require_once './server_export.php';
679 } elseif ($export_type == 'database') {
680 $active_page = 'db_export.php';
681 require_once './db_export.php';
682 } else {
683 $active_page = 'tbl_export.php';
684 require_once './tbl_export.php';
686 exit();
687 } else {
688 echo $dump_buffer;
692 * Displays the dump...
694 else {
696 * Close the html tags and add the footers in dump is displayed on screen
698 echo '</textarea>' . "\n"
699 . ' </form>' . "\n";
700 echo $back_button;
702 echo "\n";
703 echo '</div>' . "\n";
704 echo "\n";
706 <script type="text/javascript">
707 //<![CDATA[
708 var bodyWidth=null; var bodyHeight=null;
709 if (document.getElementById('textSQLDUMP')) {
710 bodyWidth = self.innerWidth;
711 bodyHeight = self.innerHeight;
712 if (!bodyWidth && !bodyHeight) {
713 if (document.compatMode && document.compatMode == "BackCompat") {
714 bodyWidth = document.body.clientWidth;
715 bodyHeight = document.body.clientHeight;
716 } else if (document.compatMode && document.compatMode == "CSS1Compat") {
717 bodyWidth = document.documentElement.clientWidth;
718 bodyHeight = document.documentElement.clientHeight;
721 document.getElementById('textSQLDUMP').style.width=(bodyWidth-50) + 'px';
722 document.getElementById('textSQLDUMP').style.height=(bodyHeight-100) + 'px';
724 //]]>
725 </script>
726 <?php
727 require './libraries/footer.inc.php';
728 } // end if