improved the zip dump feature
This commit is contained in:
@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
|
||||
$Id$
|
||||
$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>
|
||||
* add zip dump feature
|
||||
|
||||
|
@@ -515,12 +515,13 @@
|
||||
</dd>
|
||||
|
||||
<dt>
|
||||
<b>$cfgZipDump </b>boolean<br />
|
||||
<b>$cfgGZipDump </b>boolean<br />
|
||||
<b>$cfgBZipDump </b>boolean
|
||||
</dt>
|
||||
<dd>
|
||||
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.
|
||||
<br /><br />
|
||||
</dd>
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -576,12 +576,18 @@ if ($num_tables > 0) {
|
||||
<?php
|
||||
// gzip and bzip2 encode features
|
||||
if (PHP_INT_VERSION >= 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) {
|
||||
?>
|
||||
<input type="checkbox" name="zip" value="zip" onclick="return checkTransmitDump(this.form, 'zip')" /><?php echo $strZip . (($is_gzip || $is_bzip) ? ' ' : '') . "\n"; ?>
|
||||
<?php
|
||||
}
|
||||
if ($is_gzip) {
|
||||
echo "\n"
|
||||
?>
|
||||
<input type="checkbox" name="gzip" value="gzip" onclick="return checkTransmitDump(this.form, 'gzip')" /><?php echo $strGzip . (($is_bzip) ? ' ' : '') . "\n"; ?>
|
||||
<?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"; ?>
|
||||
<?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" . ' )';
|
||||
}
|
||||
}
|
||||
|
@@ -230,8 +230,8 @@ function checkFormElementInRange(theForm, theFieldName, min, max)
|
||||
|
||||
|
||||
/**
|
||||
* Ensures the choice between 'transmit', 'gzipped' and 'bzipped' checkboxes is
|
||||
* consistant
|
||||
* Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
|
||||
* checkboxes is consistant
|
||||
*
|
||||
* @param object the form
|
||||
* @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;
|
||||
|
||||
// 'gzipped' option has been checked
|
||||
if (theAction == 'gzip' && formElts['gzip'].checked) {
|
||||
// 'zipped' option has been checked
|
||||
if (theAction == 'zip' && formElts['zip'].checked) {
|
||||
if (!formElts['asfile'].checked) {
|
||||
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) {
|
||||
theForm.elements['bzip'].checked = false;
|
||||
}
|
||||
@@ -256,12 +271,18 @@ function checkTransmitDump(theForm, theAction)
|
||||
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['gzip']) != 'undefined' && formElts['gzip'].checked) {
|
||||
theForm.elements['gzip'].checked = false;
|
||||
}
|
||||
}
|
||||
// 'transmit' option has been unchecked
|
||||
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)) {
|
||||
theForm.elements['gzip'].checked = false;
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/* $Id$ */
|
||||
|
||||
|
||||
/**
|
||||
* Zip file creation class.
|
||||
* Makes zip files.
|
||||
@@ -14,32 +15,51 @@
|
||||
* by Denis125 (webmaster@atlant.ru)
|
||||
*
|
||||
* Official ZIP file format: http://www.pkware.com/appnote.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zip file class
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return
|
||||
* @access public
|
||||
*/
|
||||
|
||||
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
|
||||
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; // end of Central directory record
|
||||
/**
|
||||
* Central directory
|
||||
*
|
||||
* @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;
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
|
||||
// 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 .= "\x14\x00"; // ver needed to extract
|
||||
@@ -47,77 +67,82 @@ class zipfile
|
||||
$fr .= "\x08\x00"; // compression method
|
||||
$fr .= "\x00\x00\x00\x00"; // last mod time and date
|
||||
|
||||
// "local file header" segment
|
||||
$unc_len = strlen($data);
|
||||
$crc = crc32($data);
|
||||
$zdata = gzcompress($data);
|
||||
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
|
||||
$c_len = strlen($zdata);
|
||||
$fr .= pack("V",$crc); // crc32
|
||||
$fr .= pack("V",$c_len); // compressed filesize
|
||||
$fr .= pack("V",$unc_len); // uncompressed filesize
|
||||
$fr .= pack("v", strlen($name) ); // length of filename
|
||||
$fr .= pack("v", 0 ); // extra field length
|
||||
$fr .= pack('V', $crc); // crc32
|
||||
$fr .= pack('V', $c_len); // compressed filesize
|
||||
$fr .= pack('V', $unc_len); // uncompressed filesize
|
||||
$fr .= pack('v', strlen($name)); // length of filename
|
||||
$fr .= pack('v', 0); // extra field length
|
||||
$fr .= $name;
|
||||
// end of "local file header" segment
|
||||
|
||||
// "file data" segment
|
||||
|
||||
$fr .= $zdata;
|
||||
|
||||
// "data descriptor" segment (optional but necessary if archive is not served as file)
|
||||
|
||||
$fr .= pack("V",$crc); // crc32
|
||||
$fr .= pack("V",$c_len); // compressed filesize
|
||||
$fr .= pack("V",$unc_len); // uncompressed filesize
|
||||
// "data descriptor" segment (optional but necessary if archive is not
|
||||
// served as file)
|
||||
$fr .= pack('V', $crc); // crc32
|
||||
$fr .= pack('V', $c_len); // compressed filesize
|
||||
$fr .= pack('V', $unc_len); // uncompressed filesize
|
||||
|
||||
// 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
|
||||
$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
|
||||
$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;
|
||||
}
|
||||
} // 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
|
||||
$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
|
||||
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
|
||||
?>
|
@@ -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;
|
||||
|
@@ -885,14 +885,20 @@ echo "\n";
|
||||
<input type="checkbox" name="asfile" value="sendit" onclick="return checkTransmitDump(this.form, 'transmit')" />
|
||||
<?php echo $strSend . "\n"; ?>
|
||||
<?php
|
||||
// gzip and bzip2 encode features
|
||||
// zip, gzip and bzip2 encode features
|
||||
if (PHP_INT_VERSION >= 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) {
|
||||
?>
|
||||
<input type="checkbox" name="zip" value="zip" onclick="return checkTransmitDump(this.form, 'zip')" /><?php echo $strZip . (($is_gzip || $is_bzip) ? ' ' : '') . "\n"; ?>
|
||||
<?php
|
||||
}
|
||||
if ($is_gzip) {
|
||||
echo "\n"
|
||||
?>
|
||||
<input type="checkbox" name="gzip" value="gzip" onclick="return checkTransmitDump(this.form, 'gzip')" /><?php echo $strGzip . (($is_bzip) ? ' ' : '') . "\n"; ?>
|
||||
<?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"; ?>
|
||||
<?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" . ' )';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user