Home  >  Article  >  Backend Development  >  Example of php reading zip files (delete files, extract files, add files)

Example of php reading zip files (delete files, extract files, add files)

WBOY
WBOYOriginal
2016-07-25 08:44:11917browse
  1. /*
  2. php Extract files from zip compressed files
  3. */
  4. $zip = new ZipArchive;
  5. if ($zip->open('jQuery five-screen scrolling focus map up and down Code.zip') === TRUE) {//Chinese file names must use ANSI encoded file 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 Delete files from a zip archive
  16. */
  17. $zip = new ZipArchive;
  18. if ($zip-> ;open('ajaxupload.zip') === TRUE) {
  19. $zip->deleteName('file.txt');//Delete file
  20. $zip->deleteName('testDir/');// Delete folder
  21. $zip->close();
  22. echo 'ok';
  23. } else {
  24. echo 'failed';
  25. }
  26. ?>
  27. /*
  28. php Add a file to In the zip compressed file
  29. */
  30. $zip = new ZipArchive;
  31. if ($zip->open('ajaxupload.zip') === TRUE) {//ajaxupload.zip is an existing zip file, please note Pay attention to encoding issues with Chinese file names
  32. $zip->addFile('33.xml');//Add new files
  33. $zip->close();
  34. echo 'ok';
  35. } else {
  36. echo 'failed';
  37. }
  38. ?>
Copy code

php, zip


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn