From 9704feec19a13abaa2dbe4925150997358339b47 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 14 Mar 2011 13:52:49 +0000 Subject: [PATCH] Bugfix: Work item 15518 - PCLZip library issue References to ZipArchive Constants when ZipArchive class isn't available git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@70307 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Settings.php | 7 +++++++ Classes/PHPExcel/Shared/ZipArchive.php | 5 +++++ Classes/PHPExcel/Writer/Excel2007.php | 10 ++++++++-- changelog.txt | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Classes/PHPExcel/Settings.php b/Classes/PHPExcel/Settings.php index 3b5d7629..e157e87c 100644 --- a/Classes/PHPExcel/Settings.php +++ b/Classes/PHPExcel/Settings.php @@ -42,6 +42,13 @@ class PHPExcel_Settings const ZIPARCHIVE = 'ZipArchive'; + /** + * Reference to the class used for Zip file management + * e.g. + * ZipArchive + * + * @var string + */ private static $_zipClass = self::ZIPARCHIVE; diff --git a/Classes/PHPExcel/Shared/ZipArchive.php b/Classes/PHPExcel/Shared/ZipArchive.php index 12d306da..724e771a 100644 --- a/Classes/PHPExcel/Shared/ZipArchive.php +++ b/Classes/PHPExcel/Shared/ZipArchive.php @@ -38,6 +38,11 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php'; class PHPExcel_Shared_ZipArchive { + /** constants */ + const OVERWRITE = 'OVERWRITE'; + const CREATE = 'CREATE'; + + /** * Temporary storage directory * diff --git a/Classes/PHPExcel/Writer/Excel2007.php b/Classes/PHPExcel/Writer/Excel2007.php index b44aa7df..477d2db0 100644 --- a/Classes/PHPExcel/Writer/Excel2007.php +++ b/Classes/PHPExcel/Writer/Excel2007.php @@ -224,12 +224,18 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter $zipClass = PHPExcel_Settings::getZipClass(); $objZip = new $zipClass(); + // Retrieve OVERWRITE and CREATE constants from the instantiated zip class + // This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP + $ro = new ReflectionObject($objZip); + $zipOverWrite = $ro->getConstant('OVERWRITE'); + $zipCreate = $ro->getConstant('CREATE'); + if (file_exists($pFilename)) { unlink($pFilename); } // Try opening the ZIP file - if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) { - if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) { + if ($objZip->open($pFilename, $zipOverWrite) !== true) { + if ($objZip->open($pFilename, $zipCreate) !== true) { throw new Exception("Could not open " . $pFilename . " for writing."); } } diff --git a/changelog.txt b/changelog.txt index b880fce8..d5b5e694 100644 --- a/changelog.txt +++ b/changelog.txt @@ -25,6 +25,7 @@ Fixed in SVN: - Bugfix: (MBaker) Work item 15459 - Invalid cell coordinate in Autofilter for Excel2007 Writer +- Bugfix: (MBaker) Work item 15518 - PCLZip library issue - General: (MBaker) Work item 15405 - Two easy to fix Issues concerning PHPExcel_Token_Stack (l10n/UC) - General: (MBaker) Work item 15461 - Locale file paths not fit for windows