PHP的Zip壓縮包處理類:TbsZip
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) </ul>
示例:
$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
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!