get_set_comments.php 913 B

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