I'm trying to decompress a tar file into a directory, but have no idea how. I can extract it to the same directory as the tar file, but not into another folder.
$filename = "homedir.tar";
exec("tar xvf $filename");
Have tried the following, but it does not work (nothing is being extracted):
exec("tar -C, homedir zxvf $filename");
Update:
This is the content of my file:
# Absolute paths
$filepath = "/home/acc/public_html/test/test/homedir.tar";
$folderpath = "/home/acc/public_html/test/test/homedir";
# Check if folder exist
if(!is_dir($folderpath)) {
die('Folder does not exist');
}
# Check if folder is writable
if(!is_writable($folderpath)) {
die('Folder is not writable');
}
# Check if file exist
if(!file_exists($filepath)) {
die('File does not exist');
}
exec("tar -C $folderpath -zxvf $filepath");
No errors, but nothing is being decompresses either.
Remove the comma from the -C and add the dash before zxvf:
exec("tar -C $outdir -zxvf $infile");
Or you can put the -C part on the end and you don't need the dash before zxvf:
exec("tar zxvf $infile -C $outdir");
And you should probably make sure that your paths are absolute, just to be sure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With