Esempio n. 1
0
 public function read_file($file)
 {
     $zip = new clsTbsZip();
     $zip->Open($file);
     $content = $zip->FileRead('word/document.xml');
     $content = str_replace(array_keys($this->dbData), array_values($this->dbData), $content);
     $zip->FileReplace('word/document.xml', $content);
     $path_parts = pathinfo($file);
     $zip->Flush(TBSZIP_FILE, $this->fileFolder . '/' . $path_parts['filename'] . "MODIFIED." . $path_parts['extension']);
     $zip->close();
 }
Esempio n. 2
0
 public function actionZip()
 {
     Yii::import('application.helpers.vendors.zip.clsTbsZip');
     $zip = new clsTbsZip();
     /**create**/
     //		$zip->CreateNew();
     //
     //		$zip->FileAdd('sub/test2.txt', './public/test2.txt',TBSZIP_FILE);
     //
     //		$zip->Flush(TBSZIP_FILE, './public/zip/test.zip');
     $zipfile = './public/zip/test.zip';
     $tmpfile = './public/zip/tmp.zip';
     $zip->Open($zipfile);
     //		echo $zip->FileExists('test2.txt');
     if (!$zip->FileExists('test.txt')) {
         $zip->FileAdd('test.txt', './public/test.txt', TBSZIP_FILE);
     }
     if (!$zip->FileExists('pclzip-2-8.zip')) {
         $zip->FileAdd('pclzip-2-8.zip', './public/zip/pclzip-2-8.zip', TBSZIP_FILE);
     }
     //		$zip->FileAdd('hello.jpg', './public/uploadfiles/82671333902992.jpg', TBSZIP_FILE);
     echo $zip->FileRead('pclzip-2-8.zip');
     //		$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip');
     //		echo $zip->FileRead('test.txt');
     //		foreach ($zip->CdFileLst as $file)
     //		{
     //			UtilHelper::dump($zip->FileRead($file['v_name']));
     //		}
     $zip->Flush(TBSZIP_FILE, $tmpfile);
     //		$zip->Flush(TBSZIP_DOWNLOAD, 'download.zip', 'application/zip');
     $zip->close();
     //		if (file_exists($zipfile)){
     //			unlink($zipfile);
     //
     //			copy($tmpfile, $zipfile);
     //
     //			unlink($tmpfile);
     //		}
 }
 echo "<h4>Étude du fichier '{$file}'.</h4>\r\n";
 $extension = strtolower(substr($file, -4));
 if (!$odf->FileExists($manifest)) {
     echo "Le fichier manifest n'a pas été trouvé.<br>\r\n";
     continue;
 }
 /* debug
 	if (file_exists('manifest.xml')) {
 		$odf->FileReplace($manifest, 'manifest.xml', TBSZIP_FILE);
 		$temp = $file.'.tmp.odt';
 		$odf->Flush(TBSZIP_FILE, $temp);
 		echo "Fichier fanifest remplacé par le fichier 'manifest.xml' trouvé dans le répertoire.<br>\r\n";
 		exit;
 	}
 	*/
 $txt = $odf->FileRead($manifest);
 // des fois la version figure dans un élément <manifest:file-entry>, lé cas échéant, on va chercher la bonne version du manifeste.
 $att = ' manifest:version="';
 $p = strpos($txt, $att);
 if ($p !== false) {
     $p = $p + strlen($att);
     $p2 = strpos($txt, '"', $p);
     $version = substr($txt, $p, $p2 - $p);
     echo "La version du manifest a été trouvée : " . $version . "<br>\r\n";
 } else {
     echo "La version du manifest est absente.<br>\r\n";
 }
 $replace_manifest = 0;
 if ($extension == '.zzz') {
     echo "Pas de retouche de la version du manifest car c'est un fichier ODG.<br>\r\n";
     // osbolète
$zip = new clsTbsZip();
// create a new instance of the TbsZip class
$zip->CreateNew();
// start a new empty archive for adding files
// or
$zip->Open('an_existing_archive.zip');
// open an existing archive for reading and/or modifying
// --------------------------------------------------
// Reading information and data in the opened archive
// --------------------------------------------------
// check if a file is existing in the archive, the name must precise subfolders if any
$ok = $zip->FileExists('subfolder/help.html');
// count the files stored in the archive
$file_nbr = count($zip->CdFileLst);
// retrieve the content of an compressed file in the archive
$text1 = $zip->FileRead('readme.txt');
// retrieve the content of an compressed file in a subfolder of the archive
$text2 = $zip->FileRead('subfolder/readme.txt');
if ($ok) {
    $zip->FileExists('subfolder/help.html');
}
// -----------------------------
// Modifying data in the archive
// -----------------------------
// add a file in the archive
$zip->FileAdd('newfile.txt', $data, TBSZIP_STRING);
// add the file by giving the content
$zip->FileAdd('newpic1.png', './images/localpic1.png', TBSZIP_FILE);
// add the file by copying a local file
$zip->FileAdd('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false);
// add the uncompressed file by copying a local file
Esempio n. 5
0
 /**
  * Modify contents of docx/odt file(s) and later merged into one final document
  *
  * @param string $filePath
  *   Document file path
  * @param array $contents
  *   Content of formatted/token-replaced document
  * @param string $docType
  *   Document type e.g. odt/docx
  * @param clsTbsZip $zip
  *   Zip archive
  * @param bool $returnFinalContent
  *   Return the content of file document as a string used in unit test
  *
  * @return string
  */
 public static function printDocuments($filePath, $contents, $docType, $zip, $returnFinalContent = FALSE)
 {
     $dataMap = self::$ooxmlMap[$docType];
     $finalContent = $zip->FileRead($dataMap['dataFile']);
     // token-replaced document contents of each contact will be merged into final document
     foreach ($contents as $key => $content) {
         if ($key == 0) {
             $finalContent = $content;
             continue;
         }
         // 1. fetch the start position of document body
         // 2. later fetch only the body part starting from position $start
         // 3. replace closing body tag with pageBreak
         // 4. append the $content to the finalContent
         $start = strpos($content, $dataMap['startTag']);
         $content = substr($content, $start);
         $content = str_replace($dataMap['startTag'], $dataMap['pageBreak'], $content);
         $finalContent = str_replace($dataMap['endTag'], $content, $finalContent);
     }
     if ($returnFinalContent) {
         return $finalContent;
     }
     // Replace the loaded document file content located at $filePath with $finaContent
     $zip->FileReplace($dataMap['dataFile'], $finalContent, TBSZIP_STRING);
     $fileName = pathinfo($filePath, PATHINFO_FILENAME) . '.' . $docType;
     $zip->Flush(TBSZIP_DOWNLOAD, $fileName);
 }