How to change a folder without a full path

firstly, I am not the correct stackExchange site to post this question, if the question is for another stack site, please delete my question.

Now let's talk about the question: In this situation, there is a file that is located in: /home/user/public_html/folder-one/folder-two/folder-three/file.php , and the file should create the archive of the /folder-one with all files and subfolders of /folder-one . I am creating an archive with a system function (exec (), shell_exec () or system ()) and it works fine. My code is:

 <?php $output = 'zip -rq my-zip.zip /home/user/public_html/folder-one -x missthis/\*'; shell_exec($output); ?> 

But when I download and open the archive, the archive includes subfolders like /home ; /user ; /public_html , but these folders are completely unnecessary, and I want to know how to create zip without them.

When I try to do something like this $output = 'zip -rq my-zip.zip ../../../folder-one -x missthis/\*'; but then when i open the archive (on windows 7 OS) the name of the folder-one is ../folder-one

Postscript: it would be better if someone gives me the correct $output make zips on Windows hosting plans.

Regards, George!

+6
source share
2 answers

By default, zip will store the full path relative to the current directory. Therefore, before zip :

you must cd in public_html
 $output = 'cd /home/user/public_html; zip -rq my-zip.zip folder-one -x missthis/\*'; shell_exec($output); 
+10
source

There is a better way without doing cd . As indicated here , it is possible to ignore full paths. These are -j or --junk-paths . So you can do:

 <?php $output = 'zip -jrq my-zip.zip /home/user/public_html/folder-one -x missthis/\*'; shell_exec($output); ?> 
+2
source

Source: https://habr.com/ru/post/919620/


All Articles