Created zip file contain folder structure using tar command in PHP

≡放荡痞女 提交于 2019-12-13 07:18:32

问题


I am trying to create a zip of all files in abc folder with the name filename.zip using following command in php like:

exec(tar -cvf filename.zip /home/public_html/uploads/abc/)

but the created zip has the folder structure home/public_html/uploads. Please help me to get rid of these folders.


回答1:


exec("tar -cvf filename.zip -C /home/public_html/uploads/ abc/")

Note the space before 'abc/'. The -C switch tells tar to first change directory to /home/public_html/uploads and then compress 'abc' folder.

You could also start the command from '/home/public_html/uploads' and specify the absolute path for the output file like

chdir('/home/public_html')

exec("tar -cvf /full/path/to/filename.zip abc/")



来源:https://stackoverflow.com/questions/19927356/created-zip-file-contain-folder-structure-using-tar-command-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!