PHP的Zip压缩包处理类:TbsZip

jopen 10年前

TbsZip 是一个 PHP 的类用来读写 Zip 压缩文件包,该类无需 PHP 扩展或者是临时文件。TbsZip 可以对压缩文档中的文件进行读、写、修改和删除操作。

功能特性:

  • can read a common zip archive, or start with an empty archive
  • can modify the content of files in the archive (replace, delete or add new file)
  • the new file content can come from a PHP string, or an external physical file
  • the modified archive can be released as a new physical file, an HTTP download, or a PHP string
  • the original archive is not modified
  • the class does not use temporary files: when the new archive is flushed, unmodified parts of the archives are directly streamed from the original archive, modified parts are streamed form their sources (external physical files, or PHP string)

示例:

$zip = new clsTbsZip(); // instantiate the class    $zip->Open('archive1.zip'); // open an existing zip archive    $ok = $zip->FileExists('innerfolder/subfile1.txt'); // check if a sub-file exist in the archive    $txt = $zip->FileRead('subfile2.txt'); // retrieve the content of a sub-file    ... // some work on the $txt contents    $zip->FileReplace('subfile2.txt', $txt, TBSZIP_STRING); // replace the existing sub-file    $zip->FileReplace('subfile3.txt', false); // delete the existing sub-file    $zip->FileAdd('subfile4.txt', $txt3, TBSZIP_STRING); // add a new sub-file    $zip->Flush(TBSZIP_FILE, 'archive1_new.zip'); // flush the modifications as a new archive    $zip->Close(); // close the current archive

项目主页:http://www.open-open.com/lib/view/home/1381977436567