diff --git a/Classes/PHPExcel/Shared/ZipArchive.php b/Classes/PHPExcel/Shared/ZipArchive.php index 50e2240f5..195cd6ba8 100644 --- a/Classes/PHPExcel/Shared/ZipArchive.php +++ b/Classes/PHPExcel/Shared/ZipArchive.php @@ -111,4 +111,66 @@ public function addFromString($localname, $contents) unlink($this->_tempDir.'/'.$filenameParts["basename"]); } + /** + * Find if given fileName exist in archive (Emulate ZipArchive locateName()) + * author Adam (adam.riyadi@gmail.com) + * + * @param string $fileName Filename for the file in zip archive + * @return boolean + */ + public function locateName($name) + { + $list = $this->_zip->listContent(); + $listCount = count($list); + $list_index = -1; + for ($i = 0; $i < $listCount; $i++) { + if (strtolower($list[$i]["filename"]) == strtolower($fileName) || + strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { + $list_index = $i; + break; + } + } + return ($list_index > -1); + } + + /** + * Extract file from archive by given fileName (Emulate ZipArchive getFromName()) + * author Adam (adam.riyadi@gmail.com) + * + * @param string $fileName Filename for the file in zip archive + * @return string $contents File string contents + */ + public function getFromName($fileName) + { + $list = $this->_zip->listContent(); + $listCount = count($list); + $list_index = -1; + for ($i = 0; $i < $listCount; $i++) { + if (strtolower($list[$i]["filename"]) == strtolower($fileName) || + strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { + $list_index = $i; + break; + } + } + + $extracted = ""; + if ($list_index != -1) { + $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING); + } else { + $filename = substr($fileName, 1); + $list_index = -1; + for ($i = 0; $i < $listCount; $i++) { + if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { + $list_index = $i; + break; + } + } + $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING); + } + if ((is_array($extracted)) && ($extracted != 0)) { + $contents = $extracted[0]["content"]; + } + + return $contents; + } } diff --git a/Examples/runall.php b/Examples/runall.php index 766f8eb3c..5512b0249 100644 --- a/Examples/runall.php +++ b/Examples/runall.php @@ -35,6 +35,7 @@ // List of tests $aTests = array( '01simple.php' + , '01simplePCLZip.php' , '02types.php' , '02types-xls.php' , '03formulas.php'