Command to zip a directory using a specific direct

2020-02-18 07:15发布

I'm writing a PHP script that downloads a series of generated files (using wget) into a directory, and then zips then up, using the zip command.

The downloads work perfectly, and the zipping mostly works. I run the command:

zip -r /var/www/oraviewer/rgn_download/download/fcst_20100318_0319.zip /var/www/oraviewer/rgn_download/download/fcst_20100318_0319

which yields a zip file with all the downloaded files, but it contains the full /var/www/oraviewer/rgn_download/download/ directories, before reaching the fcst_20100318_0319/ directory.

I'm probably just missing a flag, or something small, from the zip command, but how do I get it to use fcst_20100318_0319/ as the root directory?

3条回答
Melony?
2楼-- · 2020-02-18 07:23

I have also get it worked by using this command

exec('cd '.$_SERVER['DOCUMENT_ROOT'].' && zip -r com.zip "./"');

查看更多
Summer. ? 凉城
3楼-- · 2020-02-18 07:33

I don't think zip has a flag to do that. I think the only way is something like:

cd /var/www/oraviewer/rgn_download/download/ && \
   zip -r fcst_20100318_0319.zip fcst_20100318_0319

(The backslash is just for clarity, you can remove it and put everything on one line.)

Since PHP is executing the command in a subshell, it won't change your current directory.

查看更多
成全新的幸福
4楼-- · 2020-02-18 07:44
cd /home/public_html/site/upload/ && zip -r sub_upload.zip sub_upload/
查看更多
登录 后发表回答