如何在没有完整路径的情况下压缩文件夹 [英] How to zip folder without full path
问题描述
首先,我不认为这是发布此问题的正确stackExchange网站,如果该问题是针对其他堆栈网站的,请删除我的问题.
firstly I don't which is the correct stackExchange site to post this question if the question is for other stack-site please remove my question.
现在让我们讨论这个问题:这种情况是我有一个文件位于:/home/user/public_html/folder-one/folder-two/folder-three/file.php
,并且该文件必须创建文件夹/folder-one
的存档,其中包含所有文件和子文件夹/folder-one
.我使用系统函数(exec(),shell_exec()或system())创建档案,它可以完美运行.我的代码是:
Now let talk about the question: This situation is I have a file which is located in: /home/user/public_html/folder-one/folder-two/folder-three/file.php
and the file must create archive of folder /folder-one
with all files and sub-folders of /folder-one
. I create the archive with system function (exec(), shell_exec() or system()) and it works perfect. My code is:
<?php
$output = 'zip -rq my-zip.zip /home/user/public_html/folder-one -x missthis/\*';
shell_exec($output);
?>
但是,当我下载并打开档案时,档案中的子文件夹为/home
; /user
; /public_html
,但是完全不需要此文件夹,我想知道如何在没有它们的情况下创建zip.
But when I download and open the archive the archive include the sub-folders as /home
; /user
; /public_html
but this folders are totally unneeded and I wanna know how to create zip without them.
当我尝试使用类似$output = 'zip -rq my-zip.zip ../../../folder-one -x missthis/\*';
的方法,但是当我打开存档(在基于Windows 7的操作系统上)时,文件夹1的名称为../folder-one
When I try with something like this $output = 'zip -rq my-zip.zip ../../../folder-one -x missthis/\*';
but then when I open the archive (on Windows 7 based OS) the name of folder-one is ../folder-one
后记:如果有人给我正确的答案会更好 $output
基于Windows的托管计划上的make zip.
最诚挚的问候, 乔治!
Best regards, George!
推荐答案
默认情况下,zip将存储相对于当前目录的完整路径.因此,在运行zip
之前,必须先cd
进入public_html
:
By default, zip will store the full path relative to the current directory. So you have to cd
into public_html
before running zip
:
$output = 'cd /home/user/public_html; zip -rq my-zip.zip folder-one -x missthis/\*';
shell_exec($output);
这篇关于如何在没有完整路径的情况下压缩文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!