There are some occations where we need to use extract tar file to use data into it while programming.

decompress tar file into directory

decompress tar file into directory

Here I’m going to show how to extract tar file into directory using php.
By using some commands you can easily extract tar file into directory using php.
You can use this command to extract a tar file to the same diractory itself.

exec("tar xvf $name");

Let us check how can we extract tar file into directory.

$file = "tst/a.tar";
$extract_folder = "tst/t";

if(exec("tar -C $extract_folder -xvf $file")){

  echo "success";

}else{

  echo "error";

}

You can use the above code you can extract tar file into directory using php.