Create a new is redundant
[phpmyadmin/madhuracj.git] / export.php
blob6137b96e7c3f07cb7523d2cb296b098feda2ff0c
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 $line the insert statement
129 * @return bool Whether output suceeded
131 function PMA_exportOutputHandler($line)
133 global $time_start, $dump_buffer, $dump_buffer_len, $save_filename;
135 // Kanji encoding convert feature
136 if ($GLOBALS['output_kanji_conversion']) {
137 $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : '');
139 // If we have to buffer data, we will perform everything at once at the end
140 if ($GLOBALS['buffer_needed']) {
142 $dump_buffer .= $line;
143 if ($GLOBALS['onfly_compression']) {
145 $dump_buffer_len += strlen($line);
147 if ($dump_buffer_len > $GLOBALS['memory_limit']) {
148 if ($GLOBALS['output_charset_conversion']) {
149 $dump_buffer = PMA_convert_string('utf-8', $GLOBALS['charset_of_file'], $dump_buffer);
151 // as bzipped
152 if ($GLOBALS['compression'] == 'bzip' && @function_exists('bzcompress')) {
153 $dump_buffer = bzcompress($dump_buffer);
155 // as a gzipped file
156 elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) {
157 // without the optional parameter level because it bug
158 $dump_buffer = gzencode($dump_buffer);
160 if ($GLOBALS['save_on_server']) {
161 $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer);
162 if (!$write_result || ($write_result != strlen($dump_buffer))) {
163 $GLOBALS['message'] = PMA_Message::error(__('Insufficient space to save the file %s.'));
164 $GLOBALS['message']->addParam($save_filename);
165 return false;
167 } else {
168 echo $dump_buffer;
170 $dump_buffer = '';
171 $dump_buffer_len = 0;
173 } else {
174 $time_now = time();
175 if ($time_start >= $time_now + 30) {
176 $time_start = $time_now;
177 header('X-pmaPing: Pong');
178 } // end if
180 } else {
181 if ($GLOBALS['asfile']) {
182 if ($GLOBALS['output_charset_conversion']) {
183 $line = PMA_convert_string('utf-8', $GLOBALS['charset_of_file'], $line);
185 if ($GLOBALS['save_on_server'] && strlen($line) > 0) {
186 $write_result = @fwrite($GLOBALS['file_handle'], $line);
187 if (!$write_result || ($write_result != strlen($line))) {
188 $GLOBALS['message'] = PMA_Message::error(__('Insufficient space to save the file %s.'));
189 $GLOBALS['message']->addParam($save_filename);
190 return false;
192 $time_now = time();
193 if ($time_start >= $time_now + 30) {
194 $time_start = $time_now;
195 header('X-pmaPing: Pong');
196 } // end if
197 } else {
198 // We export as file - output normally
199 echo $line;
201 } else {
202 // We export as html - replace special chars
203 echo htmlspecialchars($line);
206 return true;
207 } // end of the 'PMA_exportOutputHandler()' function
209 // Defines the default <CR><LF> format. For SQL always use \n as MySQL wants this on all platforms.
210 if ($what == 'sql') {
211 $crlf = "\n";
212 } else {
213 $crlf = PMA_whichCrlf();
216 $output_kanji_conversion = function_exists('PMA_kanji_str_conv') && $type != 'xls';
218 // Do we need to convert charset?
219 $output_charset_conversion = $asfile && $GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE
220 && isset($charset_of_file) && $charset_of_file != 'utf-8'
221 && $type != 'xls';
223 // Use on the fly compression?
224 $onfly_compression = $GLOBALS['cfg']['CompressOnFly'] && ($compression == 'gzip' || $compression == 'bzip');
225 if ($onfly_compression) {
226 $memory_limit = trim(@ini_get('memory_limit'));
227 // 2 MB as default
228 if (empty($memory_limit)) {
229 $memory_limit = 2 * 1024 * 1024;
232 if (strtolower(substr($memory_limit, -1)) == 'm') {
233 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024;
234 } elseif (strtolower(substr($memory_limit, -1)) == 'k') {
235 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024;
236 } elseif (strtolower(substr($memory_limit, -1)) == 'g') {
237 $memory_limit = (int)substr($memory_limit, 0, -1) * 1024 * 1024 * 1024;
238 } else {
239 $memory_limit = (int)$memory_limit;
242 // Some of memory is needed for other thins and as treshold.
243 // Nijel: During export I had allocated (see memory_get_usage function)
244 // approx 1.2MB so this comes from that.
245 if ($memory_limit > 1500000) {
246 $memory_limit -= 1500000;
249 // Some memory is needed for compression, assume 1/3
250 $memory_limit /= 8;
253 // Generate filename and mime type if needed
254 if ($asfile) {
255 $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
256 if ($export_type == 'server') {
257 if (isset($remember_template)) {
258 $GLOBALS['PMA_Config']->setUserValue('pma_server_filename_template',
259 'Export/file_template_server', $filename_template);
261 } elseif ($export_type == 'database') {
262 if (isset($remember_template)) {
263 $GLOBALS['PMA_Config']->setUserValue('pma_db_filename_template',
264 'Export/file_template_database', $filename_template);
266 } else {
267 if (isset($remember_template)) {
268 $GLOBALS['PMA_Config']->setUserValue('pma_table_filename_template',
269 'Export/file_template_table', $filename_template);
272 $filename = PMA_expandUserString($filename_template);
274 // convert filename to iso-8859-1, it is safer
275 $filename = PMA_convert_string('utf-8', 'iso-8859-1', $filename);
277 // Grab basic dump extension and mime type
278 // Check if the user already added extension; get the substring where the extension would be if it was included
279 $extension_start_pos = strlen($filename) - strlen($export_list[$type]['extension']) - 1;
280 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
281 $required_extension = "." . $export_list[$type]['extension'];
282 if(strtolower($user_extension) != $required_extension) {
283 $filename .= $required_extension;
285 $mime_type = $export_list[$type]['mime_type'];
287 // If dump is going to be compressed, set correct mime_type and add
288 // compression to extension
289 if ($compression == 'bzip') {
290 $filename .= '.bz2';
291 $mime_type = 'application/x-bzip2';
292 } elseif ($compression == 'gzip') {
293 $filename .= '.gz';
294 $mime_type = 'application/x-gzip';
295 } elseif ($compression == 'zip') {
296 $filename .= '.zip';
297 $mime_type = 'application/zip';
301 // Open file on server if needed
302 if ($save_on_server) {
303 $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
304 unset($message);
305 if (file_exists($save_filename) && ((!$quick_export && empty($onserverover)) || ($quick_export && $_REQUEST['quick_export_onserverover'] != 'saveitover'))) {
306 $message = PMA_Message::error(__('File %s already exists on server, change filename or check overwrite option.'));
307 $message->addParam($save_filename);
308 } else {
309 if (is_file($save_filename) && !is_writable($save_filename)) {
310 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
311 $message->addParam($save_filename);
312 } else {
313 if (!$file_handle = @fopen($save_filename, 'w')) {
314 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
315 $message->addParam($save_filename);
319 if (isset($message)) {
320 require_once './libraries/header.inc.php';
321 if ($export_type == 'server') {
322 $active_page = 'server_export.php';
323 require './server_export.php';
324 } elseif ($export_type == 'database') {
325 $active_page = 'db_export.php';
326 require './db_export.php';
327 } else {
328 $active_page = 'tbl_export.php';
329 require './tbl_export.php';
331 exit();
336 * Send headers depending on whether the user chose to download a dump file
337 * or not
339 if (!$save_on_server) {
340 if ($asfile) {
341 // Download
342 // (avoid rewriting data containing HTML with anchors and forms;
343 // this was reported to happen under Plesk)
344 @ini_set('url_rewriter.tags','');
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('utf-8', $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