From cf20f92e199364a9893430b3ac68dafbdaa158e9 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Fri, 18 Feb 2011 21:29:16 +0000 Subject: [PATCH] Task #225 Replace zip and unzip by PHP object. It is not needed anymore to use the function system --- include/class_acc_bilan.php | 43 ++++++++++++++++++++++++++++++++----- include/class_document.php | 22 ++++++++++++++++--- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/include/class_acc_bilan.php b/include/class_acc_bilan.php index eea37a931..5411af9a4 100644 --- a/include/class_acc_bilan.php +++ b/include/class_acc_bilan.php @@ -353,8 +353,18 @@ class Acc_Bilan exit(); } ob_start(); - system('unzip "'.$work_file.'"'); - ob_end_clean(); + /* unzip the document */ + $zip = new Zip_Extended; + if ($zip->open($work_file) === TRUE) + { + $zip->extractTo($dirname.DIRECTORY_SEPARATOR); + $zip->close(); + } else + { + echo __FILE__.":".__LINE__."cannot unzip model ".$filename; + } + + ob_end_clean(); unlink($work_file); // remove the zip file $p_file=fopen('content.xml','r'); @@ -624,8 +634,22 @@ class Acc_Bilan echo "Je ne peux pas ouvrir ce fichier "; exit(); } - system('unzip "'.$work_file.'"'); - // remove the zip file + /* + * unzip the document + */ + ob_start(); + $zip = new Zip_Extended; + if ($zip->open($work_file) === TRUE) + { + $zip->extractTo($dirname.DIRECTORY_SEPARATOR); + $zip->close(); + } + else + { + echo __FILE__.":".__LINE__."cannot unzip model ".$filename; + } + + // Remove the file we do not need anymore unlink ($work_file); @@ -643,7 +667,16 @@ class Acc_Bilan exit(); } // repack - system ('zip -r "'.$this->b_name.'.'.$this->b_type.'" *'); + $zip = new Zip_Extended; + $res = $zip->open($this->b_name.".".$this->b_type, ZipArchive::CREATE); + if($res !== TRUE) + { + echo __FILE__.":".__LINE__."cannot recreate zip"; + exit; + } + $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR); + $zip->close(); + ob_end_clean(); fclose($p_file); $fdoc=fopen($dirname.DIRECTORY_SEPARATOR.$this->b_name.'.'.$this->b_type,'r'); diff --git a/include/class_document.php b/include/class_document.php index 889ca390d..421763692 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -23,6 +23,7 @@ require_once('class_acc_account_ledger.php'); require_once('class_action.php'); require_once('class_acc_tva.php'); require_once('class_user.php'); +require_once('class_zip_extended.php'); /*! \file * \brief Class Document corresponds to the table document @@ -102,7 +103,14 @@ class Document if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 ) { ob_start(); - system("unzip '".$filename."'"); + $zip = new Zip_Extended; + if ($zip->open($filename) === TRUE) { + $zip->extractTo($dirname.DIRECTORY_SEPARATOR); + $zip->close(); + } else { + echo __FILE__.":".__LINE__."cannot unzip model ".$filename; + } + // Remove the file we do not need anymore unlink($filename); ob_end_clean(); @@ -122,9 +130,17 @@ class Document if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 ) { ob_start(); - system ("zip -r ".$filename." *"); + $zip = new Zip_Extended; + $res = $zip->open($filename, ZipArchive::CREATE); + if($res !== TRUE) + { + echo __FILE__.":".__LINE__."cannot recreate zip"; + exit; + } + $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR); + $zip->close(); + ob_end_clean(); - echo " "; $file_to_parse=$filename; }