From 55963749dbf86ea04df460af98338210f3dfea02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chapeaux?= Date: Sun, 23 Sep 2001 09:06:29 +0000 Subject: [PATCH] improved the zip dump feature --- ChangeLog | 6 ++ Documentation.html | 5 +- config.inc.php3 | 5 +- db_details.php3 | 18 ++-- libraries/functions.js | 29 +++++- libraries/zip.lib.php3 | 201 +++++++++++++++++++++++------------------ tbl_dump.php3 | 34 +++---- tbl_properties.php3 | 18 ++-- 8 files changed, 186 insertions(+), 130 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fcf99da8..49fe12cb7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ phpMyAdmin - Changelog $Id$ $Source$ +2001-09-23 Loïc Chapeaux + * config.inc.php3; Documentation.html; db_details.php3; tbl_dump.php3; + tbl_properties.php3; libraries/functions.php3; libraries/zip.lib.php3: + improved the zip dump feature. + * lang/*: added $strZip where it was missing. + 2001-09-23 Armel Fauveau * add zip dump feature diff --git a/Documentation.html b/Documentation.html index 84d927d3c..35da3eada 100755 --- a/Documentation.html +++ b/Documentation.html @@ -515,12 +515,13 @@
+ $cfgZipDump boolean
$cfgGZipDump boolean
$cfgBZipDump boolean
- Defines whether to allow the use of gzip/bzip compression when creating - a dump file or not. + Defines whether to allow the use of zip/gzip/bzip compression when + creating a dump file or not.

diff --git a/config.inc.php3 b/config.inc.php3 index 16b670e6f..80757a88f 100755 --- a/config.inc.php3 +++ b/config.inc.php3 @@ -121,8 +121,9 @@ $cfgProtectBinary = 'blob'; // disallow editing of binary fields in edit // 'blob' allow editing except for BLOB fields // 'all' disallow editing -$cfgGZipDump = TRUE; // Allow the use of gzip/bzip compression -$cfgBZipDump = TRUE; // for dump files +$cfgZipDump = TRUE; // Allow the use of zip/gzip/bzip +$cfgGZipDump = TRUE; // compression for +$cfgBZipDump = TRUE; // dump files /** diff --git a/db_details.php3 b/db_details.php3 index da6522817..bad8d0199 100755 --- a/db_details.php3 +++ b/db_details.php3 @@ -576,12 +576,18 @@ if ($num_tables > 0) { = 40004) { + $is_zip = (isset($cfgZipDump) && $cfgZipDump && @function_exists('gzcompress')); $is_gzip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzencode')); $is_bzip = (isset($cfgBZipDump) && $cfgBZipDump && @function_exists('bzcompress')); - $is_zip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzcompress')); - if ($is_gzip || $is_bzip || $is_zip) { - echo "\n" . ' ('; + if ($is_zip || $is_gzip || $is_bzip) { + echo "\n" . ' (' . "\n"; + if ($is_zip) { + ?> + + 0) { - - datasec[] = $fr; + // add this entry to array + $this -> datasec[] = $fr; + $new_offset = strlen(implode('', $this->datasec)); - $new_offset = strlen(implode("", $this->datasec)); + // now add to central directory record + $cdrec = "\x50\x4b\x01\x02"; + $cdrec .= "\x00\x00"; // version made by + $cdrec .= "\x14\x00"; // version needed to extract + $cdrec .= "\x00\x00"; // gen purpose bit flag + $cdrec .= "\x08\x00"; // compression method + $cdrec .= "\x00\x00\x00\x00"; // last mod time & date + $cdrec .= pack('V', $crc); // crc32 + $cdrec .= pack('V', $c_len); // compressed filesize + $cdrec .= pack('V', $unc_len); // uncompressed filesize + $cdrec .= pack('v', strlen($name) ); // length of filename + $cdrec .= pack('v', 0 ); // extra field length + $cdrec .= pack('v', 0 ); // file comment length + $cdrec .= pack('v', 0 ); // disk number start + $cdrec .= pack('v', 0 ); // internal file attributes + $cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set - // now add to central directory record - - $cdrec = "\x50\x4b\x01\x02"; - $cdrec .="\x00\x00"; // version made by - $cdrec .="\x14\x00"; // version needed to extract - $cdrec .="\x00\x00"; // gen purpose bit flag - $cdrec .="\x08\x00"; // compression method - $cdrec .="\x00\x00\x00\x00"; // last mod time & date - $cdrec .= pack("V",$crc); // crc32 - $cdrec .= pack("V",$c_len); // compressed filesize - $cdrec .= pack("V",$unc_len); // uncompressed filesize - $cdrec .= pack("v", strlen($name) ); // length of filename - $cdrec .= pack("v", 0 ); // extra field length - $cdrec .= pack("v", 0 ); // file comment length - $cdrec .= pack("v", 0 ); // disk number start - $cdrec .= pack("v", 0 ); // internal file attributes - $cdrec .= pack("V", 32 ); // external file attributes - 'archive' bit set - - $cdrec .= pack("V", $this -> old_offset ); // relative offset of local header - $this -> old_offset = $new_offset; + $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header + $this -> old_offset = $new_offset; $cdrec .= $name; - - // optional extra field, file comment goes here - // save to central directory - - $this -> ctrl_dir[] = $cdrec; - } - function file() { // dump out file - $data = implode("", $this -> datasec); - $ctrldir = implode("", $this -> ctrl_dir); + // optional extra field, file comment goes here + // save to central directory + $this -> ctrl_dir[] = $cdrec; + } // end of the 'add_file()' method - return - $data. - $ctrldir. - $this -> eof_ctrl_dir. - pack("v", sizeof($this -> ctrl_dir)). // total # of entries "on this disk" - pack("v", sizeof($this -> ctrl_dir)). // total # of entries overall - pack("V", strlen($ctrldir)). // size of central dir - pack("V", strlen($data)). // offset to start of central dir - "\x00\x00"; // .zip file comment length - } -} -?> \ No newline at end of file + + /** + * Dumps out file + * + * @return string the zipped file + * + * @access public + */ + function file() + { + $data = implode('', $this -> datasec); + $ctrldir = implode('', $this -> ctrl_dir); + + return + $data . + $ctrldir . + $this -> eof_ctrl_dir . + pack('v', sizeof($this -> ctrl_dir)) . // total # of entries "on this disk" + pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall + pack('V', strlen($ctrldir)) . // size of central dir + pack('V', strlen($data)) . // offset to start of central dir + "\x00\x00"; // .zip file comment length + } // end of the 'file()' method + +} // end of the 'zipfile' class +?> diff --git a/tbl_dump.php3 b/tbl_dump.php3 index 49459001b..af7929977 100755 --- a/tbl_dump.php3 +++ b/tbl_dump.php3 @@ -65,6 +65,7 @@ require('./libraries/common.lib.php3'); require('./libraries/build_dump.lib.php3'); require('./libraries/zip.lib.php3'); + /** * Increase time limit for script execution and initializes some variables */ @@ -78,7 +79,7 @@ $crlf = which_crlf(); * Ensure zipped formats are associated with the download feature */ if (empty($asfile) - && (!empty($gzip) || !empty($bzip) || !empty($zip))) { + && (!empty($zip) || !empty($gzip) || !empty($bzip))) { $asfile = 1; } @@ -243,31 +244,32 @@ else { /** * "Displays" the dump... */ -// 1. as a bzipped file -if (isset($bzip) && $bzip == 'bzip') { +// 1. as a gzipped file +if (isset($zip) && $zip == 'zip') { + if (PHP_INT_VERSION >= 40000 && @function_exists('gzcompress')) { + if ($what == 'csv' || $what == 'excel') { + $extbis = '.csv'; + } else { + $extbis = '.sql'; + } + $zipfile = new zipfile(); + $zipfile -> add_file($dump_buffer, $filename . $extbis); + echo $zipfile -> file(); + } +} +// 2. as a bzipped file +else if (isset($bzip) && $bzip == 'bzip') { if (PHP_INT_VERSION >= 40004 && @function_exists('bzcompress')) { echo bzcompress($dump_buffer); } } -// 2. as a gzipped file +// 3. as a gzipped file else if (isset($gzip) && $gzip == 'gzip') { if (PHP_INT_VERSION >= 40004 && @function_exists('gzencode')) { // without the optional parameter level because it bug echo gzencode($dump_buffer); } } -// 3. as a gzipped file -else if (isset($zip) && $zip == 'zip') { - if (PHP_INT_VERSION >= 40000 && @function_exists('gzcompress')) { - if ($what == 'csv' || $what == 'excel') - $extbis='.csv'; - else - $extbis='.sql'; - $zipfile = new zipfile(); - $zipfile -> add_file($dump_buffer, $filename . $extbis); - echo $zipfile -> file(); - } -} // 4. on screen else { echo $dump_buffer; diff --git a/tbl_properties.php3 b/tbl_properties.php3 index a64bc4c53..ca758bdc1 100755 --- a/tbl_properties.php3 +++ b/tbl_properties.php3 @@ -885,14 +885,20 @@ echo "\n"; = 40004) { + $is_zip = (isset($cfgZipDump) && $cfgZipDump && @function_exists('gzcompress')); $is_gzip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzencode')); $is_bzip = (isset($cfgBZipDump) && $cfgBZipDump && @function_exists('bzcompress')); - $is_zip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzcompress')); - if ($is_gzip || $is_bzip) { + if ($is_zip || $is_gzip || $is_bzip) { echo "\n" . ' (' . "\n"; + if ($is_zip) { + ?> + + = 40004) { - -