get_set_comments.php 898 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. copy('test_with_comment.zip', 't.zip');
  3. $z = new ZipArchive;
  4. $z->open('t.zip');
  5. print_r($z);
  6. for ($i=0; $i<$z->numFiles; $i++) {
  7. echo "index: $i\n";
  8. print_r($z->getCommentIndex($i));
  9. echo "\n\n";
  10. }
  11. echo "foobar/ " . $z->getCommentName('foobar/') . "\n";
  12. echo "Archive comment: " . $z->getArchiveComment() . "\n";
  13. $z->setCommentIndex(1, 'new comment idx 1');
  14. $z->setCommentName('foobar/', 'new comment foobar/');
  15. $z->setArchiveComment( 'new archive comment');
  16. for ($i=0; $i<$z->numFiles; $i++) {
  17. echo "index: $i\n";
  18. print_r($z->getCommentIndex($i));
  19. echo "\n\n";
  20. }
  21. echo $z->getCommentName('foobar/') . "\n";
  22. // Get the original comment
  23. echo $z->getCommentName('foobar/', ZIPARCHIVE::FL_UNCHANGED) . "\n";
  24. echo "Archive comment: " . $z->getArchiveComment() . "\n";
  25. echo "Archive comment (original): " . $z->getArchiveComment(ZIPARCHIVE::FL_UNCHANGED) . "\n";