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); // } }
// 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 // delete an existing file in the archive $zip->FileReplace('newfile.txt', $data, TBSZIP_STRING); // replace the file by giving the content $zip->FileReplace('newpic1.png', './images/localpic1.png', TBSZIP_FILE); // replace the file by copying a local file $zip->FileReplace('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false); // replace the uncompressed file by copying a local file $zip->FileReplace('newpic3.png', false); // delete the file in the archive // cancel the last modification on the file (add/replace/delete)