create.php 706 B

1234567891011121314151617181920212223
  1. <?php
  2. error_reporting(E_ALL);
  3. if (!extension_loaded('zip')) {
  4. dl('zip.so');
  5. }
  6. $thisdir = dirname(__FILE__);
  7. unlink("./test112.zip");
  8. $zip = new ZipArchive();
  9. $filename = "./test112.zip";
  10. if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
  11. exit("cannot open <$filename>\n");
  12. } else {
  13. echo "file <$filename> OK\n";
  14. }
  15. $zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
  16. $zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
  17. $zip->addFile($thisdir . "/too.php","/testfromfile.php");
  18. echo "numfiles: " . $zip->numFiles . "\n";
  19. echo "status:" . $zip->status . "\n";
  20. $zip->close();
  21. unset($zip);