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

查看:31
本文介绍了从 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天全站免登陆