从zip归档文件创建和提取文件 [英] Creating and extracting files from zip archives

查看:135
本文介绍了从zip归档文件创建和提取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在用于在php中创建/提取zip文件的库?

Is there a library for crating/extracting zip files in php?

ZipArchive类工作异常,并且在php.net上提到了这一点: (对于我检查过的每个功能)

The ZipArchive class works erratically, and this is mentioned on php.net : (for every function I checked)

ZipArchive :: addEmptyDir (没有可用的版本信息,可能仅在CVS中提供)

ZipArchive::addEmptyDir (No version information available, might be only in CVS)

推荐答案

好,我检查了 http://pear.php.net/package/Archive_Zip 由Irmantas发布,
但是它是这样的:
此软件包已不再维护,已被取代.软件包已移至pecl.php.net频道zip." 然后我搜索了pear.php.net并偶然发现: http://pear.php.net/package/File_Archive

Ok, I checked http://pear.php.net/package/Archive_Zip as posted by Irmantas,
but it says this :
"This package is not maintained anymore and has been superseded. Package has moved to channel pecl.php.net, package zip." Then I searched pear.php.net and stumbled upon : http://pear.php.net/package/File_Archive

File_Archive没有非常直观的方法集. 但是我想要制作tar文件的简单功能,并且 从tar文件中提取文件.

File_Archive doesn't have a very intuitive set of methods though. But I wanted simple functionality of making a tar file, and extracting files from a tar file.

以下摘录实现了以下目的: 从tar文件中提取文件->

Following snippets achieve that : Extracting files from a tar file ->

<?php
require_once "File/Archive.php";
$tmp = 'output';
$t1 = 'check.tar';
File_Archive::setOption('tmpDirectory','tmp');
$r = File_Archive::extract(
    File_Archive::read($t1.'/'),
    File_Archive::toFiles($tmp)
);
?>

将文件添加到tar文件->

Adding files to a tar file ->

<?php
require_once "Archive.php";
$dir = "../../mysql/data/blackStone/";
$files[0] = "";
$i = 0;
          if ($dh = opendir($dir)) {
              while (($file = readdir($dh)) !== false ) {
              if( $file != "." && $file != ".." )
                $files[$i++] = $dir.$file;
          }
      }

File_Archive::extract(
    $files,
    File_Archive::toArchive(
        'check.tar',
        File_Archive::toOutput()
    )
);

?>

这篇关于从zip归档文件创建和提取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆