PHP read the zip file (delete file, extract file, add File) instance

Source: Internet
Author: User
Tags ziparchive
  1. /*
  2. PHP extracts files from zip compressed files
  3. */
  4. $zip = new Ziparchive;
  5. if ($zip->open (' jquery five screen up and down scrolling focus graph code. zip ') = = = TRUE) {//Chinese file name to use ANSI-encoded files format
  6. $zip->extractto (' foldername ');//Extract All Files
  7. $zip->extractto ('/my/destination/dir/', Array (' pear_item.gif ', ' testfromfile.php '));//Extract some files
  8. $zip->close ();
  9. echo ' OK ';
  10. } else {
  11. Echo ' failed ';
  12. }
  13. ?>
  14. /*
  15. PHP removes files from a zip archive
  16. */
  17. $zip = new Ziparchive;
  18. if ($zip->open (' ajaxupload.zip ') = = = TRUE) {
  19. $zip->deletename (' file.txt ');//delete files
  20. $zip->deletename (' testdir/');//Delete folder
  21. $zip->close ();
  22. echo ' OK ';
  23. } else {
  24. Echo ' failed ';
  25. }
  26. ?>
  27. /*
  28. PHP adds a file to the ZIP archive
  29. */
  30. $zip = new Ziparchive;
  31. if ($zip->open (' ajaxupload.zip ') = = = TRUE) {//ajaxupload.zip is an existing zip file, note that the Chinese file name should pay attention to the encoding problem
  32. $zip->addfile (' 33.xml ');//Add a new file
  33. $zip->close ();
  34. echo ' OK ';
  35. } else {
  36. Echo ' failed ';
  37. }
  38. ?>
Copy Code
PHP, zip
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.