[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_4_1RC1-1268-g5e557a8
Michal Čihař
nijel at users.sourceforge.net
Tue May 17 15:30:19 CEST 2011
The branch, master has been updated
via 5e557a89b7362aad1e11250659345256354389c8 (commit)
via 69f164291f8792dbf0d8641b25a08b49515fad1f (commit)
via c38b3ad1ce6e2012ff01d5e61d4632c12aacb418 (commit)
via 39210c606d8239d3a000cb2181e11b7fe47a5284 (commit)
from d6b8d71f95b9c41b11de35a69269213e9902a5c8 (commit)
- Log -----------------------------------------------------------------
commit 5e557a89b7362aad1e11250659345256354389c8
Author: Michal Čihař <mcihar at novell.com>
Date: Tue May 17 15:29:22 2011 +0200
Create file without storing in memory
commit 69f164291f8792dbf0d8641b25a08b49515fad1f
Author: Michal Čihař <mcihar at novell.com>
Date: Tue May 17 15:23:08 2011 +0200
Avoid duplicating code
commit c38b3ad1ce6e2012ff01d5e61d4632c12aacb418
Author: Michal Čihař <mcihar at novell.com>
Date: Tue May 17 15:21:49 2011 +0200
Whitespace cleanup
commit 39210c606d8239d3a000cb2181e11b7fe47a5284
Author: Brian Carcich <drbitboy at users.sourceforge.net>
Date: Tue May 17 15:21:15 2011 +0200
Add support to output zip content on the fly.
-----------------------------------------------------------------------
Summary of changes:
libraries/zip.lib.php | 48 +++++++++++++++++++++++++++++++++++++++---------
webapp.php | 9 +++++----
2 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/libraries/zip.lib.php b/libraries/zip.lib.php
index a8bcb98..443b173 100644
--- a/libraries/zip.lib.php
+++ b/libraries/zip.lib.php
@@ -28,6 +28,13 @@
class zipfile
{
/**
+ * Whether to echo zip as it's built or return as string from -> file
+ *
+ * @var boolean $doWrite
+ */
+ var $doWrite = false;
+
+ /**
* Array to store compressed data
*
* @var array $datasec
@@ -57,6 +64,21 @@ class zipfile
/**
+ * Sets member variable this -> doWrite to true
+ * - Should be called immediately after class instantiantion
+ * - If set to true, then ZIP archive are echo'ed to STDOUT as each
+ * file is added via this -> addfile(), and central directories are
+ * echoed to STDOUT on final call to this -> file(). Also,
+ * this -> file() returns an empty string so it is safe to issue a
+ * "echo $zipfile;" command
+ *
+ * @access public
+ */
+ function setDoWrite() {
+ $this -> doWrite = true;
+ } // end of the 'setDoWrite()' method
+
+ /**
* Converts an Unix timestamp to a four byte DOS date and time format (date
* in high two bytes, time in low two bytes allowing magnitude comparison).
*
@@ -133,8 +155,12 @@ class zipfile
//$fr .= pack('V', $c_len); // compressed filesize
//$fr .= pack('V', $unc_len); // uncompressed filesize
- // add this entry to array
- $this -> datasec[] = $fr;
+ // echo this entry on the fly, ...
+ if ( $this -> doWrite) {
+ echo $fr;
+ } else { // ... OR add this entry to array
+ $this -> datasec[] = $fr;
+ }
// now add to central directory record
$cdrec = "\x50\x4b\x01\x02";
@@ -165,26 +191,30 @@ class zipfile
/**
- * Dumps out file
+ * Echo central dir if ->doWrite==true, else build string to return
*
- * @return string the zipped file
+ * @return string if ->doWrite {empty string} else the ZIP file contents
*
* @access public
*/
function file()
{
- $data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
-
- return
- $data .
- $ctrldir .
+ $header = $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
+
+ if ( $this -> doWrite ) { // Send central directory & end ctrl dir to STDOUT
+ echo $header;
+ return ""; // Return empty string
+ } else { // Return entire ZIP archive as string
+ $data = implode('', $this -> datasec);
+ return $data . $header;
+ }
} // end of the 'file()' method
} // end of the 'zipfile' class
diff --git a/webapp.php b/webapp.php
index 86d6bf1..cdc0a87 100644
--- a/webapp.php
+++ b/webapp.php
@@ -44,11 +44,12 @@ foreach ($parameters as $key => $value) {
$ini_file .= $key . '=' . $value . "\n";
}
+header('Content-Type: application/webapp');
+header('Content-Disposition: attachment; filename="' . $name . '"');
+
$zip = new zipfile;
+$zip->setDoWrite();
$zip->addFile($ini_file, 'webapp.ini');
$zip->addFile(file_get_contents($icon), 'phpMyAdmin.ico');
-
-header('Content-Type: application/webapp');
-header('Content-Disposition: attachment; filename="' . $name . '"');
-echo $zip->file();
+$zip->file();
?>
hooks/post-receive
--
phpMyAdmin
More information about the Git
mailing list