improved the zip dump feature

This commit is contained in:
Loïc Chapeaux
2001-09-23 09:06:29 +00:00
parent 50c734d0bb
commit 55963749db
8 changed files with 186 additions and 130 deletions

View File

@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2001-09-23 Lo<4C>c Chapeaux <lolo@phpheaven.net>
* 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 <armel.fauveau@globalis-ms.com> 2001-09-23 Armel Fauveau <armel.fauveau@globalis-ms.com>
* add zip dump feature * add zip dump feature

View File

@@ -515,12 +515,13 @@
</dd> </dd>
<dt> <dt>
<b>$cfgZipDump </b>boolean<br />
<b>$cfgGZipDump </b>boolean<br /> <b>$cfgGZipDump </b>boolean<br />
<b>$cfgBZipDump </b>boolean <b>$cfgBZipDump </b>boolean
</dt> </dt>
<dd> <dd>
Defines whether to allow the use of gzip/bzip compression when creating Defines whether to allow the use of zip/gzip/bzip compression when
a dump file or not. creating a dump file or not.
<br /><br /> <br /><br />
</dd> </dd>

View File

@@ -121,8 +121,9 @@ $cfgProtectBinary = 'blob'; // disallow editing of binary fields in edit
// 'blob' allow editing except for BLOB fields // 'blob' allow editing except for BLOB fields
// 'all' disallow editing // 'all' disallow editing
$cfgGZipDump = TRUE; // Allow the use of gzip/bzip compression $cfgZipDump = TRUE; // Allow the use of zip/gzip/bzip
$cfgBZipDump = TRUE; // for dump files $cfgGZipDump = TRUE; // compression for
$cfgBZipDump = TRUE; // dump files
/** /**

View File

@@ -576,12 +576,18 @@ if ($num_tables > 0) {
<?php <?php
// gzip and bzip2 encode features // gzip and bzip2 encode features
if (PHP_INT_VERSION >= 40004) { if (PHP_INT_VERSION >= 40004) {
$is_zip = (isset($cfgZipDump) && $cfgZipDump && @function_exists('gzcompress'));
$is_gzip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzencode')); $is_gzip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzencode'));
$is_bzip = (isset($cfgBZipDump) && $cfgBZipDump && @function_exists('bzcompress')); $is_bzip = (isset($cfgBZipDump) && $cfgBZipDump && @function_exists('bzcompress'));
$is_zip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzcompress')); if ($is_zip || $is_gzip || $is_bzip) {
if ($is_gzip || $is_bzip || $is_zip) { echo "\n" . ' (' . "\n";
echo "\n" . ' ('; if ($is_zip) {
?>
<input type="checkbox" name="zip" value="zip" onclick="return checkTransmitDump(this.form, 'zip')" /><?php echo $strZip . (($is_gzip || $is_bzip) ? '&nbsp;' : '') . "\n"; ?>
<?php
}
if ($is_gzip) { if ($is_gzip) {
echo "\n"
?> ?>
<input type="checkbox" name="gzip" value="gzip" onclick="return checkTransmitDump(this.form, 'gzip')" /><?php echo $strGzip . (($is_bzip) ? '&nbsp;' : '') . "\n"; ?> <input type="checkbox" name="gzip" value="gzip" onclick="return checkTransmitDump(this.form, 'gzip')" /><?php echo $strGzip . (($is_bzip) ? '&nbsp;' : '') . "\n"; ?>
<?php <?php
@@ -592,12 +598,6 @@ if ($num_tables > 0) {
<input type="checkbox" name="bzip" value="bzip" onclick="return checkTransmitDump(this.form, 'bzip')" /><?php echo $strBzip . "\n"; ?> <input type="checkbox" name="bzip" value="bzip" onclick="return checkTransmitDump(this.form, 'bzip')" /><?php echo $strBzip . "\n"; ?>
<?php <?php
} }
if ($is_zip) {
echo "\n"
?>
<input type="checkbox" name="zip" value="zip" onclick="return checkTransmitDump(this.form, 'zip')" /><?php echo $strZip . "\n"; ?>
<?php
}
echo "\n" . ' )'; echo "\n" . ' )';
} }
} }

View File

@@ -230,8 +230,8 @@ function checkFormElementInRange(theForm, theFieldName, min, max)
/** /**
* Ensures the choice between 'transmit', 'gzipped' and 'bzipped' checkboxes is * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
* consistant * checkboxes is consistant
* *
* @param object the form * @param object the form
* @param string a code for the action that causes this function to be run * @param string a code for the action that causes this function to be run
@@ -242,11 +242,26 @@ function checkTransmitDump(theForm, theAction)
{ {
var formElts = theForm.elements; var formElts = theForm.elements;
// 'gzipped' option has been checked // 'zipped' option has been checked
if (theAction == 'gzip' && formElts['gzip'].checked) { if (theAction == 'zip' && formElts['zip'].checked) {
if (!formElts['asfile'].checked) { if (!formElts['asfile'].checked) {
theForm.elements['asfile'].checked = true; theForm.elements['asfile'].checked = true;
} }
if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
theForm.elements['gzip'].checked = false;
}
if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
theForm.elements['bzip'].checked = false;
}
}
// 'gzipped' option has been checked
else if (theAction == 'gzip' && formElts['gzip'].checked) {
if (!formElts['asfile'].checked) {
theForm.elements['asfile'].checked = true;
}
if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
theForm.elements['zip'].checked = false;
}
if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) { if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
theForm.elements['bzip'].checked = false; theForm.elements['bzip'].checked = false;
} }
@@ -256,12 +271,18 @@ function checkTransmitDump(theForm, theAction)
if (!formElts['asfile'].checked) { if (!formElts['asfile'].checked) {
theForm.elements['asfile'].checked = true; theForm.elements['asfile'].checked = true;
} }
if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
theForm.elements['zip'].checked = false;
}
if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) { if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
theForm.elements['gzip'].checked = false; theForm.elements['gzip'].checked = false;
} }
} }
// 'transmit' option has been unchecked // 'transmit' option has been unchecked
else if (theAction == 'transmit' && !formElts['asfile'].checked) { else if (theAction == 'transmit' && !formElts['asfile'].checked) {
if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
theForm.elements['zip'].checked = false;
}
if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) { if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
theForm.elements['gzip'].checked = false; theForm.elements['gzip'].checked = false;
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/* $Id$ */ /* $Id$ */
/** /**
* Zip file creation class. * Zip file creation class.
* Makes zip files. * Makes zip files.
@@ -14,32 +15,51 @@
* by Denis125 (webmaster@atlant.ru) * by Denis125 (webmaster@atlant.ru)
* *
* Official ZIP file format: http://www.pkware.com/appnote.txt * Official ZIP file format: http://www.pkware.com/appnote.txt
*/
/**
* Zip file class
* *
* @param * @access public
*
* @return
*/ */
class zipfile class zipfile
{ {
/**
* Array to store compressed data
*
* @var array $datasec
*/
var $datasec = array();
var $datasec = array(); // array to store compressed data /**
var $ctrl_dir = array(); // central directory * Central directory
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; // end of Central directory record *
* @var array $ctrl_dir
*/
var $ctrl_dir = array();
/**
* End of central directory record
*
* @var string $eof_ctrl_dir
*/
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
/**
* Last offset position
*
* @var integer $old_offset
*/
var $old_offset = 0; var $old_offset = 0;
/**
* Adds "file" to archive
*
* @param string file contents
* @param string name of the file in the archive (may contains the path)
*
* @access public
*/
function add_file($data, $name) function add_file($data, $name)
// adds "file" to archive
// $data - file contents
// $name - name of file in archive. Add path if your want
{ {
$name = str_replace("\\", "/", $name); $name = str_replace('\\', '/', $name);
$fr = "\x50\x4b\x03\x04"; $fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00"; // ver needed to extract $fr .= "\x14\x00"; // ver needed to extract
@@ -47,77 +67,82 @@ class zipfile
$fr .= "\x08\x00"; // compression method $fr .= "\x08\x00"; // compression method
$fr .= "\x00\x00\x00\x00"; // last mod time and date $fr .= "\x00\x00\x00\x00"; // last mod time and date
// "local file header" segment
$unc_len = strlen($data); $unc_len = strlen($data);
$crc = crc32($data); $crc = crc32($data);
$zdata = gzcompress($data); $zdata = gzcompress($data);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
$c_len = strlen($zdata); $c_len = strlen($zdata);
$fr .= pack("V",$crc); // crc32 $fr .= pack('V', $crc); // crc32
$fr .= pack("V",$c_len); // compressed filesize $fr .= pack('V', $c_len); // compressed filesize
$fr .= pack("V",$unc_len); // uncompressed filesize $fr .= pack('V', $unc_len); // uncompressed filesize
$fr .= pack("v", strlen($name) ); // length of filename $fr .= pack('v', strlen($name)); // length of filename
$fr .= pack("v", 0 ); // extra field length $fr .= pack('v', 0); // extra field length
$fr .= $name; $fr .= $name;
// end of "local file header" segment
// "file data" segment // "file data" segment
$fr .= $zdata; $fr .= $zdata;
// "data descriptor" segment (optional but necessary if archive is not served as file) // "data descriptor" segment (optional but necessary if archive is not
// served as file)
$fr .= pack("V",$crc); // crc32 $fr .= pack('V', $crc); // crc32
$fr .= pack("V",$c_len); // compressed filesize $fr .= pack('V', $c_len); // compressed filesize
$fr .= pack("V",$unc_len); // uncompressed filesize $fr .= pack('V', $unc_len); // uncompressed filesize
// add this entry to array // add this entry to array
$this -> datasec[] = $fr; $this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
$new_offset = strlen(implode("", $this->datasec));
// now add to central directory record // now add to central directory record
$cdrec = "\x50\x4b\x01\x02"; $cdrec = "\x50\x4b\x01\x02";
$cdrec .= "\x00\x00"; // version made by $cdrec .= "\x00\x00"; // version made by
$cdrec .= "\x14\x00"; // version needed to extract $cdrec .= "\x14\x00"; // version needed to extract
$cdrec .= "\x00\x00"; // gen purpose bit flag $cdrec .= "\x00\x00"; // gen purpose bit flag
$cdrec .= "\x08\x00"; // compression method $cdrec .= "\x08\x00"; // compression method
$cdrec .= "\x00\x00\x00\x00"; // last mod time & date $cdrec .= "\x00\x00\x00\x00"; // last mod time & date
$cdrec .= pack("V",$crc); // crc32 $cdrec .= pack('V', $crc); // crc32
$cdrec .= pack("V",$c_len); // compressed filesize $cdrec .= pack('V', $c_len); // compressed filesize
$cdrec .= pack("V",$unc_len); // uncompressed filesize $cdrec .= pack('V', $unc_len); // uncompressed filesize
$cdrec .= pack("v", strlen($name) ); // length of filename $cdrec .= pack('v', strlen($name) ); // length of filename
$cdrec .= pack("v", 0 ); // extra field length $cdrec .= pack('v', 0 ); // extra field length
$cdrec .= pack("v", 0 ); // file comment length $cdrec .= pack('v', 0 ); // file comment length
$cdrec .= pack("v", 0 ); // disk number start $cdrec .= pack('v', 0 ); // disk number start
$cdrec .= pack("v", 0 ); // internal file attributes $cdrec .= pack('v', 0 ); // internal file attributes
$cdrec .= pack("V", 32 ); // external file attributes - 'archive' bit set $cdrec .= pack('V', 32 ); // external file attributes - 'archive' bit set
$cdrec .= pack("V", $this -> old_offset ); // relative offset of local header $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
$this -> old_offset = $new_offset; $this -> old_offset = $new_offset;
$cdrec .= $name; $cdrec .= $name;
// optional extra field, file comment goes here // optional extra field, file comment goes here
// save to central directory // save to central directory
$this -> ctrl_dir[] = $cdrec; $this -> ctrl_dir[] = $cdrec;
} } // end of the 'add_file()' method
function file() { // dump out file
$data = implode("", $this -> datasec); /**
$ctrldir = implode("", $this -> ctrl_dir); * Dumps out file
*
* @return string the zipped file
*
* @access public
*/
function file()
{
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
return return
$data . $data .
$ctrldir . $ctrldir .
$this -> eof_ctrl_dir . $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 "on this disk"
pack("v", sizeof($this -> ctrl_dir)). // total # of entries overall pack('v', sizeof($this -> ctrl_dir)) . // total # of entries overall
pack("V", strlen($ctrldir)). // size of central dir pack('V', strlen($ctrldir)) . // size of central dir
pack("V", strlen($data)). // offset to start of central dir pack('V', strlen($data)) . // offset to start of central dir
"\x00\x00"; // .zip file comment length "\x00\x00"; // .zip file comment length
} } // end of the 'file()' method
}
} // end of the 'zipfile' class
?> ?>

View File

@@ -65,6 +65,7 @@ require('./libraries/common.lib.php3');
require('./libraries/build_dump.lib.php3'); require('./libraries/build_dump.lib.php3');
require('./libraries/zip.lib.php3'); require('./libraries/zip.lib.php3');
/** /**
* Increase time limit for script execution and initializes some variables * 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 * Ensure zipped formats are associated with the download feature
*/ */
if (empty($asfile) if (empty($asfile)
&& (!empty($gzip) || !empty($bzip) || !empty($zip))) { && (!empty($zip) || !empty($gzip) || !empty($bzip))) {
$asfile = 1; $asfile = 1;
} }
@@ -243,31 +244,32 @@ else {
/** /**
* "Displays" the dump... * "Displays" the dump...
*/ */
// 1. as a bzipped file // 1. as a gzipped file
if (isset($bzip) && $bzip == 'bzip') { 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')) { if (PHP_INT_VERSION >= 40004 && @function_exists('bzcompress')) {
echo bzcompress($dump_buffer); echo bzcompress($dump_buffer);
} }
} }
// 2. as a gzipped file // 3. as a gzipped file
else if (isset($gzip) && $gzip == 'gzip') { else if (isset($gzip) && $gzip == 'gzip') {
if (PHP_INT_VERSION >= 40004 && @function_exists('gzencode')) { if (PHP_INT_VERSION >= 40004 && @function_exists('gzencode')) {
// without the optional parameter level because it bug // without the optional parameter level because it bug
echo gzencode($dump_buffer); 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 // 4. on screen
else { else {
echo $dump_buffer; echo $dump_buffer;

View File

@@ -885,14 +885,20 @@ echo "\n";
<input type="checkbox" name="asfile" value="sendit" onclick="return checkTransmitDump(this.form, 'transmit')" /> <input type="checkbox" name="asfile" value="sendit" onclick="return checkTransmitDump(this.form, 'transmit')" />
<?php echo $strSend . "\n"; ?> <?php echo $strSend . "\n"; ?>
<?php <?php
// gzip and bzip2 encode features // zip, gzip and bzip2 encode features
if (PHP_INT_VERSION >= 40004) { if (PHP_INT_VERSION >= 40004) {
$is_zip = (isset($cfgZipDump) && $cfgZipDump && @function_exists('gzcompress'));
$is_gzip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzencode')); $is_gzip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzencode'));
$is_bzip = (isset($cfgBZipDump) && $cfgBZipDump && @function_exists('bzcompress')); $is_bzip = (isset($cfgBZipDump) && $cfgBZipDump && @function_exists('bzcompress'));
$is_zip = (isset($cfgGZipDump) && $cfgGZipDump && @function_exists('gzcompress')); if ($is_zip || $is_gzip || $is_bzip) {
if ($is_gzip || $is_bzip) {
echo "\n" . ' (' . "\n"; echo "\n" . ' (' . "\n";
if ($is_zip) {
?>
<input type="checkbox" name="zip" value="zip" onclick="return checkTransmitDump(this.form, 'zip')" /><?php echo $strZip . (($is_gzip || $is_bzip) ? '&nbsp;' : '') . "\n"; ?>
<?php
}
if ($is_gzip) { if ($is_gzip) {
echo "\n"
?> ?>
<input type="checkbox" name="gzip" value="gzip" onclick="return checkTransmitDump(this.form, 'gzip')" /><?php echo $strGzip . (($is_bzip) ? '&nbsp;' : '') . "\n"; ?> <input type="checkbox" name="gzip" value="gzip" onclick="return checkTransmitDump(this.form, 'gzip')" /><?php echo $strGzip . (($is_bzip) ? '&nbsp;' : '') . "\n"; ?>
<?php <?php
@@ -903,12 +909,6 @@ if (PHP_INT_VERSION >= 40004) {
<input type="checkbox" name="bzip" value="bzip" onclick="return checkTransmitDump(this.form, 'bzip')" /><?php echo $strBzip . "\n"; ?> <input type="checkbox" name="bzip" value="bzip" onclick="return checkTransmitDump(this.form, 'bzip')" /><?php echo $strBzip . "\n"; ?>
<?php <?php
} }
if ($is_zip) {
echo "\n"
?>
<input type="checkbox" name="zip" value="zip" onclick="return checkTransmitDump(this.form, 'zip')" /><?php echo $strZip . "\n"; ?>
<?php
}
echo "\n" . ' )'; echo "\n" . ' )';
} }
} }