设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 171|回复: 0

Some code examples for TbsZip

[复制链接]
发表于 2014-2-28 14:20:56 | 显示全部楼层 |阅读模式
本帖最后由 demo 于 2014-3-1 06:22 编辑

Some code examples for TbsZip
  1. include_once('tbszip.php'); // load the TbsZip library
  2. $zip = new clsTbsZip(); // create a new instance of the TbsZip class


  3. $zip->CreateNew(); // start a new empty archive for adding files
  4. // or
  5. $zip->Open('an_existing_archive.zip'); // open an existing archive for reading and/or modifying


  6. // --------------------------------------------------
  7. // Reading information and data in the opened archive
  8. // --------------------------------------------------

  9. // check if a file is existing in the archive, the name must precise subfolders if any
  10. $ok = $zip->FileExists('subfolder/help.html');

  11. // count the files stored in the archive
  12. $file_nbr = count($zip->CdFileLst);

  13. // retrieve the content of an compressed file in the archive
  14. $text1 = $zip->FileRead('readme.txt');

  15. // retrieve the content of an compressed file in a subfolder of the archive
  16. $text2 = $zip->FileRead('subfolder/readme.txt');


  17. if ($ok) $zip->FileExists('subfolder/help.html');

  18. // -----------------------------
  19. // Modifying data in the archive
  20. // -----------------------------

  21. // add a file in the archive
  22. $zip->FileAdd('newfile.txt', $data, TBSZIP_STRING); // add the file by giving the content
  23. $zip->FileAdd('newpic1.png', './images/localpic1.png', TBSZIP_FILE);        // add the file by copying a local file
  24. $zip->FileAdd('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false); // add the uncompressed file by copying a local file

  25. // delete an existing file in the archive
  26. $zip->FileReplace('newfile.txt', $data, TBSZIP_STRING); // replace the file by giving the content
  27. $zip->FileReplace('newpic1.png', './images/localpic1.png', TBSZIP_FILE);        // replace the file by copying a local file
  28. $zip->FileReplace('newpic2.png', './images/localpic2.png', TBSZIP_FILE, false); // replace the uncompressed file by copying a local file
  29. $zip->FileReplace('newpic3.png', false);                                        // delete the file in the archive

  30. // cancel the last modification on the file (add/replace/delete)
  31. $zip->FileCancelModif('newpic2.png');

  32. // ----------------------
  33. // Applying modifications
  34. // ----------------------

  35. $zip->Flush(TBSZIP_FILE, './save/new_archive.zip'); // apply modifications as a new local file

  36. // apply modifications as an HTTP downloaded file
  37. $zip->Flush(TBSZIP_DOWNLOAD, 'download.zip');
  38. $zip->Flush(TBSZIP_DOWNLOAD, 'download.zip', 'application/zip'); // with a specific Content-Type

  39. // apply modifications as a downloaded file with your customized HTTP headers
  40. header("Content-type: application/force-download");
  41. header("Content-Disposition: attachment; filename=download.zip");
  42. header("Expires: Fri, 01 Jan 2010 05:00:00 GMT");
  43. $zip->Flush(TBSZIP_DOWNLOAD+TBSZIP_NOHEADER);


  44. // -----------------
  45. // Close the archive
  46. // -----------------

  47. $zip->Close(); // stop to work with the opened archive. Modifications are not applied to the opened archive, use Flush() to commit  
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )  

GMT-8, 2025-8-26 13:50 , Processed in 0.014668 second(s), 18 queries .

Supported by Best Deal Online X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表