Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompress tar file into directory

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.

like image 768
Kenneth Poulsen Avatar asked Oct 24 '22 01:10

Kenneth Poulsen


1 Answers

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.

like image 174
Kevin Avatar answered Oct 30 '22 17:10

Kevin