Reputation: 5
I am creating an encrypting ZIP backup of my project. I am using exec() command
to archive the files and folder with encryption in PHP but the issue is - the files and folder are archives from the root directory but I want a specific folder to archive.
I also try to change the directory multiples time but it same also starts from home3
in cpanel.
below the code, I am using for archive -
$path = realpath('./../../'); //CORRECT DIR
$password = "test";
$zipFileName = "backup.zip";
exec ("zip -r -P {$password} {$zipFileName} {$path}");
OUTPUT Archive directory : home3\USERNAME\public_html\DOMAIN\FOLDER
I want it to achieve only \FOLDER DIR
Upvotes: 0
Views: 1676
Reputation: 23
Should be a simple fix by just adding cd $path &&
to the beginning of the exec
command:
exec("cd $path && zip -r -P {$password} {$zipFileName} {$path}");
Edit:
Mind, that the generated zip file is now in the specified $path
directory.
So you might also want to move the file to a specific folder by adding the wanted location in front of {$zipFileName}
:
Edit 2:
I think exec("cd $path && zip -r -P {$password} /wanted/location/{$zipFileName} *");
is what you want.
Upvotes: 1