Uncompress the tar file into a directory

I am trying to unzip a tar file into a directory, but have no idea how to do this. I can extract it to the same directory as the tar file, but not to another folder.

$filename = "homedir.tar";
exec("tar xvf $filename");

We tried the following, but it does not work (nothing is retrieved):

exec("tar -C, homedir zxvf $filename");

Update:

This is the contents 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 unpacked.

+5
source share
1 answer

Remove the comma from -C and add the slash before zxvf:

exec("tar -C $outdir -zxvf $infile");

Or you can put the -C part at the end, and you don't need a dash before zxvf:

exec("tar zxvf $infile -C $outdir");

And you should probably make sure your paths are absolute, just to be sure.

+3
source

All Articles