创建的zip文件包含使用PHP中的tar命令的文件夹结构


Created zip file contain folder structure using tar command in PHP

我正在尝试使用以下命令在 abc 文件夹中创建文件名为 filename 的所有文件的 zip.zip,如下所示:

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

但是创建的zip具有文件夹结构主页/public_html/上传。请帮助我摆脱这些文件夹。

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

请注意"abc/"前面的空格。-C 开关告诉 tar 首先将目录更改为/home/public_html/uploads,然后压缩"abc"文件夹。

您也可以从"/home/public_html/uploads"开始命令并指定输出文件的绝对路径,例如

chdir('/home/public_html')

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