How to zip a whole folder using PHP

前端 未结 15 2577
有刺的猬
有刺的猬 2020-11-22 08:48

I have found here at stackoveflow some codes on how to ZIP a specific file, but how about a specific folder?

Folder/
  index.html
  picture.jpg
  important.tx         


        
15条回答
  •  青春惊慌失措
    2020-11-22 09:09

    I assume this is running on a server where the zip application is in the search path. Should be true for all unix-based and I guess most windows-based servers.

    exec('zip -r archive.zip "My folder"');
    unlink('My\ folder/index.html');
    unlink('My\ folder/picture.jpg');
    

    The archive will reside in archive.zip afterwards. Keep in mind that blanks in file or folder names are a common cause of errors and should be avoided where possible.

提交回复
热议问题