Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将tar文件解压缩到目录中_Php_Exec_Tar_Compression - Fatal编程技术网

Php 将tar文件解压缩到目录中

Php 将tar文件解压缩到目录中,php,exec,tar,compression,Php,Exec,Tar,Compression,我试图将一个tar文件解压缩到一个目录中,但不知道如何。 我可以将它解压缩到与tar文件相同的目录中,但不能解压缩到另一个文件夹中 $filename = "homedir.tar"; exec("tar xvf $filename"); 已尝试以下操作,但无效(未提取任何内容): 更新: 这是我的文件的内容: # Absolute paths $filepath = "/home/acc/public_html/test/test/homedir.tar"; $folderpath = "/

我试图将一个tar文件解压缩到一个目录中,但不知道如何。 我可以将它解压缩到与tar文件相同的目录中,但不能解压缩到另一个文件夹中

$filename = "homedir.tar";
exec("tar xvf $filename");
已尝试以下操作,但无效(未提取任何内容):

更新:

这是我的文件的内容:

# 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");

没有错误,但也没有解压缩任何内容。

从-C中删除逗号,并在zxvf之前添加破折号:

exec("tar -C $outdir -zxvf $infile");
exec("tar zxvf $infile -C $outdir");
或者,您可以将-C部分放在末端,而不需要在zxvf之前使用破折号:

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

您可能应该确保您的路径是绝对的,只是为了确保。

您的Web服务器上是否安装了pear tar?尝试将空数组作为第二个参数传递,然后检查该数组的内容。它将向您显示所有的输出,这可能会给您一个错误的线索。请参阅:我尝试过,返回空$status=array();exec(“tar-C$folderpath-zxvf$filepath”,$status);打印(状态);在我的错误日志中获取此信息:[06-Sep-2011 14:39:11]PHP警告:模块“json”已在第0行的未知位置加载