set_compression.php 623 B

123456789101112131415161718192021
  1. <?php
  2. error_reporting(E_ALL);
  3. if (!extension_loaded('zip')) {
  4. dl('zip.so');
  5. }
  6. $zip = new ZipArchive();
  7. $filename = "a.zip";
  8. if (!$zip->open($filename, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) {
  9. exit("cannot open <$filename>\n");
  10. }
  11. $zip->addFromString("testfilephp.txt", "#1 This is a test string added as testfilephp.txt.\n");
  12. $zip->addFromString("testfilephp2.txt", "#2 This is a test string added as testfilephp2.txt.\n");
  13. $zip->addFile("too.php", "testfromfile.php");
  14. $zip->setCompressionName("testfilephp2.txt", ZipArchive::CM_STORE);
  15. $zip->setCompressionIndex(2, ZipArchive::CM_STORE);
  16. $zip->close();