没有 exec() 的 PHP Untar-gz?

标签 php exec tar

如何在不使用 exec('tar') 或任何其他命令的情况下使用纯 PHP 在 php 中解压缩文件?

我的问题如下;我有一个 26mb 的 tar.gz 文件需要上传到我的服务器并解压缩。我试过用net2ftp解压,但不支持tar.gz上传后解压。

我使用的是免费网络主机,所以他们不允许任何 exec() 命令,也不允许访问提示。那么我将如何解开它呢?

PHP 有内置命令吗?

最佳答案

从 PHP 5.3.0 开始,您不需要使用 Archive_Tar

有一个新的类可以处理 tar 存档:The PharData class .

提取文件(使用 PharData::extractTo(),其工作方式类似于 ZipArchive::extractTo()):

try {
    $phar = new PharData('myphar.tar');
    $phar->extractTo('/full/path'); // extract all files
} catch (Exception $e) {
    // handle errors
}

如果您有 tar.gz 存档,只需在解压前解压缩(使用 PharData::decompress()):

// decompress from gz
$p = new PharData('/path/to/my.tar.gz');
$p->decompress(); // creates /path/to/my.tar

// unarchive from the tar
$phar = new PharData('/path/to/my.tar');
$phar->extractTo('/full/path');

关于没有 exec() 的 PHP Untar-gz?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9416508/

相关文章:

java - 为什么我的解压包不包含最后一个字节

maven - 如何在 maven 中为 tar 文件创建 MD5 校验和

php - Symfony2 无法连接到 sqlite

php - Post 方法在 PHP 中不起作用

php - 如何获取与mysql中的concat值字段相关的COUNT和INNER JOIN

php - FFMpeg 在命令行中工作,但不在 PHP 中使用 exec();

linux - 在Linux上提取分割的.tar文件,需要单独解密

javascript - <输入类型 ="date"> 在 mozilla 中不起作用

php - 运行 "Last"Linux 命令

c - C语言中的多管道( children 不停读)