Merge branch 'master' of ssh://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/crack.git] / export.php
blob7da25fc051639067c4d5a35493a6a9d37976aaba
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);
275 // convert filename to iso-8859-1, it is safer
276 $filename = PMA_convert_string($charset, 'iso-8859-1', $filename);
278 // Grab basic dump extension and mime type
279 // Check if the user already added extension; get the substring where the extension would be if it was included
280 $extension_start_pos = strlen($filename) - strlen($export_list[$type]['extension']) - 1;
281 $user_extension = substr($filename, $extension_start_pos, strlen($filename));
282 $required_extension = "." . $export_list[$type]['extension'];
283 if(strtolower($user_extension) != $required_extension) {
284 $filename .= $required_extension;
286 $mime_type = $export_list[$type]['mime_type'];
288 // If dump is going to be compressed, set correct mime_type and add
289 // compression to extension
290 if ($compression == 'bzip') {
291 $filename .= '.bz2';
292 $mime_type = 'application/x-bzip2';
293 } elseif ($compression == 'gzip') {
294 $filename .= '.gz';
295 $mime_type = 'application/x-gzip';
296 } elseif ($compression == 'zip') {
297 $filename .= '.zip';
298 $mime_type = 'application/zip';
302 // Open file on server if needed
303 if ($save_on_server) {
304 $save_filename = PMA_userDir($cfg['SaveDir']) . preg_replace('@[/\\\\]@', '_', $filename);
305 unset($message);
306 if (file_exists($save_filename) && ((!$quick_export && empty($onserverover)) || ($quick_export && $_REQUEST['quick_export_onserverover'] != 'saveitover'))) {
307 $message = PMA_Message::error(__('File %s already exists on server, change filename or check overwrite option.'));
308 $message->addParam($save_filename);
309 } else {
310 if (is_file($save_filename) && !is_writable($save_filename)) {
311 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
312 $message->addParam($save_filename);
313 } else {
314 if (!$file_handle = @fopen($save_filename, 'w')) {
315 $message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
316 $message->addParam($save_filename);
320 if (isset($message)) {
321 require_once './libraries/header.inc.php';
322 if ($export_type == 'server') {
323 $active_page = 'server_export.php';
324 require './server_export.php';
325 } elseif ($export_type == 'database') {
326 $active_page = 'db_export.php';
327 require './db_export.php';
328 } else {
329 $active_page = 'tbl_export.php';
330 require './tbl_export.php';
332 exit();
337 * Send headers depending on whether the user chose to download a dump file
338 * or not
340 if (!$save_on_server) {
341 if ($asfile) {
342 // Download
343 // (avoid rewriting data containing HTML with anchors and forms;
344 // this was reported to happen under Plesk)
345 @ini_set('url_rewriter.tags','');
347 header('Content-Type: ' . $mime_type);
348 header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
349 // Tested behavior of
350 // IE 5.50.4807.2300
351 // IE 6.0.2800.1106 (small glitch, asks twice when I click Open)
352 // IE 6.0.2900.2180
353 // Firefox 1.0.6
354 // in http and https
355 header('Content-Disposition: attachment; filename="' . $filename . '"');
356 if (PMA_USR_BROWSER_AGENT == 'IE') {
357 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
358 header('Pragma: public');
359 } else {
360 header('Pragma: no-cache');
361 // test case: exporting a database into a .gz file with Safari
362 // would produce files not having the current time
363 // (added this header for Safari but should not harm other browsers)
364 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
366 } else {
367 // HTML
368 if ($export_type == 'database') {
369 $num_tables = count($tables);
370 if ($num_tables == 0) {
371 $message = PMA_Message::error(__('No tables found in database.'));
372 require_once './libraries/header.inc.php';
373 $active_page = 'db_export.php';
374 require './db_export.php';
375 exit();
378 $backup_cfgServer = $cfg['Server'];
379 require_once './libraries/header.inc.php';
380 $cfg['Server'] = $backup_cfgServer;
381 unset($backup_cfgServer);
382 echo "\n" . '<div align="' . $cell_align_left . '">' . "\n";
383 //echo ' <pre>' . "\n";
386 * Displays a back button with all the $_REQUEST data in the URL (store in a variable to also display after the textarea)
388 $back_button = '<p>[ <a href="';
389 if ($export_type == 'server') {
390 $back_button .= 'server_export.php?' . PMA_generate_common_url();
391 } elseif ($export_type == 'database') {
392 $back_button .= 'db_export.php?' . PMA_generate_common_url($db);
393 } else {
394 $back_button .= 'tbl_export.php?' . PMA_generate_common_url($db, $table);
397 // Convert the multiple select elements from an array to a string
398 if($export_type == 'server' && isset($_REQUEST['db_select'])) {
399 $_REQUEST['db_select'] = implode(",", $_REQUEST['db_select']);
400 } elseif($export_type == 'database' && isset($_REQUEST['table_select'])) {
401 $_REQUEST['table_select'] = implode(",", $_REQUEST['table_select']);
404 foreach($_REQUEST as $name => $value) {
405 $back_button .= '&' . urlencode($name) . '=' . urlencode($value);
407 $back_button .= '&repopulate=1">Back</a> ]</p>';
409 echo $back_button;
410 echo ' <form name="nofunction">' . "\n"
411 // remove auto-select for now: there is no way to select
412 // only a part of the text; anyway, it should obey
413 // $cfg['TextareaAutoSelect']
414 //. ' <textarea name="sqldump" cols="50" rows="30" onclick="this.select();" id="textSQLDUMP" wrap="OFF">' . "\n";
415 . ' <textarea name="sqldump" cols="50" rows="30" id="textSQLDUMP" wrap="OFF">' . "\n";
416 } // end download
419 // Fake loop just to allow skip of remain of this code by break, I'd really
420 // need exceptions here :-)
421 do {
423 // Add possibly some comments to export
424 if (!PMA_exportHeader()) {
425 break;
428 // Will we need relation & co. setup?
429 $do_relation = isset($GLOBALS[$what . '_relation']);
430 $do_comments = isset($GLOBALS[$what . '_include_comments']);
431 $do_mime = isset($GLOBALS[$what . '_mime']);
432 if ($do_relation || $do_comments || $do_mime) {
433 $cfgRelation = PMA_getRelationsParam();
435 if ($do_mime) {
436 require_once './libraries/transformations.lib.php';
439 // Include dates in export?
440 $do_dates = isset($GLOBALS[$what . '_dates']);
443 * Builds the dump
445 // Gets the number of tables if a dump of a database has been required
446 if ($export_type == 'server') {
447 if (isset($db_select)) {
448 $tmp_select = implode($db_select, '|');
449 $tmp_select = '|' . $tmp_select . '|';
451 // Walk over databases
452 foreach ($GLOBALS['pma']->databases as $current_db) {
453 if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
454 || !isset($tmp_select)) {
455 if (!PMA_exportDBHeader($current_db)) {
456 break 2;
458 if (!PMA_exportDBCreate($current_db)) {
459 break 2;
461 if (function_exists('PMA_exportRoutines') && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && isset($GLOBALS['sql_procedure_function'])) {
462 PMA_exportRoutines($current_db);
465 $tables = PMA_DBI_get_tables($current_db);
466 $views = array();
467 foreach ($tables as $table) {
468 // if this is a view, collect it for later; views must be exported
469 // after the tables
470 $is_view = PMA_Table::isView($current_db, $table);
471 if ($is_view) {
472 $views[] = $table;
474 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
475 // for a view, export a stand-in definition of the table
476 // to resolve view dependencies
477 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)) {
478 break 3;
481 // if this is a view or a merge table, don't export data
482 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !($is_view || PMA_Table::isMerge($current_db, $table))) {
483 $local_query = 'SELECT * FROM ' . PMA_backquote($current_db) . '.' . PMA_backquote($table);
484 if (!PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) {
485 break 3;
488 // now export the triggers (needs to be done after the data because
489 // triggers can modify already imported tables)
490 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
491 if (!PMA_exportStructure($current_db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
492 break 2;
496 foreach($views as $view) {
497 // no data export for a view
498 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
499 if (!PMA_exportStructure($current_db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
500 break 3;
504 if (!PMA_exportDBFooter($current_db)) {
505 break 2;
509 } elseif ($export_type == 'database') {
510 if (!PMA_exportDBHeader($db)) {
511 break;
514 if (function_exists('PMA_exportRoutines') && strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false && isset($GLOBALS['sql_procedure_function'])) {
515 PMA_exportRoutines($db);
518 $i = 0;
519 $views = array();
520 // $tables contains the choices from the user (via $table_select)
521 foreach ($tables as $table) {
522 // if this is a view, collect it for later; views must be exported after
523 // the tables
524 $is_view = PMA_Table::isView($db, $table);
525 if ($is_view) {
526 $views[] = $table;
528 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
529 // for a view, export a stand-in definition of the table
530 // to resolve view dependencies
531 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'stand_in' : 'create_table', $export_type)) {
532 break 2;
535 // if this is a view or a merge table, don't export data
536 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && !($is_view || PMA_Table::isMerge($db, $table))) {
537 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table);
538 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
539 break 2;
542 // now export the triggers (needs to be done after the data because
543 // triggers can modify already imported tables)
544 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
545 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
546 break 2;
550 foreach ($views as $view) {
551 // no data export for a view
552 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
553 if (!PMA_exportStructure($db, $view, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'create_view', $export_type)) {
554 break 2;
559 if (!PMA_exportDBFooter($db)) {
560 break;
562 } else {
563 if (!PMA_exportDBHeader($db)) {
564 break;
566 // We export just one table
567 // $allrows comes from the form when "Dump all rows" has been selected
568 if ($allrows == '0' && $limit_to > 0 && $limit_from >= 0) {
569 $add_query = ' LIMIT '
570 . (($limit_from > 0) ? $limit_from . ', ' : '')
571 . $limit_to;
572 } else {
573 $add_query = '';
576 $is_view = PMA_Table::isView($db, $table);
577 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
578 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, $is_view ? 'create_view' : 'create_table', $export_type)) {
579 break;
582 // If this is an export of a single view, we have to export data;
583 // for example, a PDF report
584 // if it is a merge table, no data is exported
585 if (($GLOBALS[$what . '_structure_or_data'] == 'data' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') && ! PMA_Table::isMerge($db, $table)) {
586 if (!empty($sql_query)) {
587 // only preg_replace if needed
588 if (!empty($add_query)) {
589 // remove trailing semicolon before adding a LIMIT
590 $sql_query = preg_replace('%;\s*$%', '', $sql_query);
592 $local_query = $sql_query . $add_query;
593 PMA_DBI_select_db($db);
594 } else {
595 $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . $add_query;
597 if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
598 break;
601 // now export the triggers (needs to be done after the data because
602 // triggers can modify already imported tables)
603 if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
604 if (!PMA_exportStructure($db, $table, $crlf, $err_url, $do_relation, $do_comments, $do_mime, $do_dates, 'triggers', $export_type)) {
605 break 2;
608 if (!PMA_exportDBFooter($db)) {
609 break;
612 if (!PMA_exportFooter()) {
613 break;
616 } while (false);
617 // End of fake loop
619 if ($save_on_server && isset($message)) {
620 require_once './libraries/header.inc.php';
621 if ($export_type == 'server') {
622 $active_page = 'server_export.php';
623 require './server_export.php';
624 } elseif ($export_type == 'database') {
625 $active_page = 'db_export.php';
626 require './db_export.php';
627 } else {
628 $active_page = 'tbl_export.php';
629 require './tbl_export.php';
631 exit();
635 * Send the dump as a file...
637 if (!empty($asfile)) {
638 // Convert the charset if required.
639 if ($output_charset_conversion) {
640 $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer);
643 // Do the compression
644 // 1. as a zipped file
645 if ($compression == 'zip') {
646 if (@function_exists('gzcompress')) {
647 $zipfile = new zipfile();
648 $zipfile -> addFile($dump_buffer, substr($filename, 0, -4));
649 $dump_buffer = $zipfile -> file();
652 // 2. as a bzipped file
653 elseif ($compression == 'bzip') {
654 if (@function_exists('bzcompress')) {
655 $dump_buffer = bzcompress($dump_buffer);
658 // 3. as a gzipped file
659 elseif ($compression == 'gzip') {
660 if (@function_exists('gzencode') && !@ini_get('zlib.output_compression')) {
661 // without the optional parameter level because it bug
662 $dump_buffer = gzencode($dump_buffer);
666 /* If ve saved on server, we have to close file now */
667 if ($save_on_server) {
668 $write_result = @fwrite($file_handle, $dump_buffer);
669 fclose($file_handle);
670 if (strlen($dump_buffer) !=0 && (!$write_result || ($write_result != strlen($dump_buffer)))) {
671 $message = new PMA_Message(__('Insufficient space to save the file %s.'), PMA_Message::ERROR, $save_filename);
672 } else {
673 $message = new PMA_Message(__('Dump has been saved to file %s.'), PMA_Message::SUCCESS, $save_filename);
676 require_once './libraries/header.inc.php';
677 if ($export_type == 'server') {
678 $active_page = 'server_export.php';
679 require_once './server_export.php';
680 } elseif ($export_type == 'database') {
681 $active_page = 'db_export.php';
682 require_once './db_export.php';
683 } else {
684 $active_page = 'tbl_export.php';
685 require_once './tbl_export.php';
687 exit();
688 } else {
689 echo $dump_buffer;
693 * Displays the dump...
695 else {
697 * Close the html tags and add the footers in dump is displayed on screen
699 echo '</textarea>' . "\n"
700 . ' </form>' . "\n";
701 echo $back_button;
703 echo "\n";
704 echo '</div>' . "\n";
705 echo "\n";
707 <script type="text/javascript">
708 //<![CDATA[
709 var bodyWidth=null; var bodyHeight=null;
710 if (document.getElementById('textSQLDUMP')) {
711 bodyWidth = self.innerWidth;
712 bodyHeight = self.innerHeight;
713 if (!bodyWidth && !bodyHeight) {
714 if (document.compatMode && document.compatMode == "BackCompat") {
715 bodyWidth = document.body.clientWidth;
716 bodyHeight = document.body.clientHeight;
717 } else if (document.compatMode && document.compatMode == "CSS1Compat") {
718 bodyWidth = document.documentElement.clientWidth;
719 bodyHeight = document.documentElement.clientHeight;
722 document.getElementById('textSQLDUMP').style.width=(bodyWidth-50) + 'px';
723 document.getElementById('textSQLDUMP').style.height=(bodyHeight-100) + 'px';
725 //]]>
726 </script>
727 <?php
728 require './libraries/footer.inc.php';
729 } // end if