创建的zip文件包含使用tar命令在PHP中的文件夹结构 [英] Created zip file contain folder structure using tar command in PHP

查看:240
本文介绍了创建的zip文件包含使用tar命令在PHP中的文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用以下命令在php中创建一个名为filename.zip的abc文件夹中的所有文件的zip:

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/)

但创建的zip具有文件夹结构home / public_html / uploads。请帮助我摆脱这些文件夹。

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

推荐答案

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

请注意'abc / -C开关指示tar首先将目录更改为/ 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.

您也可以从'/ home / public_html / uploads'并指定输出文件的绝对路径,如

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 /)

这篇关于创建的zip文件包含使用tar命令在PHP中的文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆