将 tar 文件解压到目录中
我正在尝试将 tar 文件解压缩到目录中,但不知道如何解压。 我可以将其提取到与 tar 文件相同的目录,但不能提取到另一个文件夹中。
$filename = "homedir.tar";
exec("tar xvf $filename");
已尝试以下操作,但它不起作用(没有提取任何内容):
exec("tar -C, homedir zxvf $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");
没有错误,但也没有解压缩任何内容。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 -C 中删除逗号并在 zxvf: 之前添加破折号:
或者您可以将 -C 部分放在末尾,并且 zxvf: 之前不需要破折号:
而且您应该确保您的路径是绝对的,只是为了务必。
Remove the comma from the -C and add the dash before zxvf:
Or you can put the -C part on the end and you don't need the dash before zxvf:
And you should probably make sure that your paths are absolute, just to be sure.