承接 originphp/zip 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

originphp/zip

Composer 安装命令:

composer require originphp/zip

包简介

OriginPHP Zip

README 文档

README

license build coverage

A ZIP utility for creating and unziping ZIP files.

Installation

To install this package

$ composer require originphp/zip

Static Methods

The static methods provide a quick way to zip and unzip archives.

Create a ZIP Archive

To create a ZIP archive using a file or directory

Zip::zip(__DIR__ .'/src','/backups/today.zip');

You can also ZIP multiple files or directories

Zip::zip([
    'README.md',
    __DIR__ .'/src'
    ],'/backups/today.zip');

You can also pass any of the following options keys

  • password: a password used to encrypt the archive with
  • compress: default:true. Set to false to only store the files (without compression)
  • encryption: default:aes256. This is the encryption method used when using a password. Supported encryption methods: aes128,aes192,and aes256.

To encrypt files with passwords you need to be using PHP 7.3 or above.

Zip::zip(__DIR__ .'/src','/backups/today.zip',[
    'password'=>'passw0rd'
    ]);

Unzip a ZIP Archive

To unzip a ZIP file

Zip::unzip('/backups/today.zip','/a/folder');

If any of the files are encrypted you provide a password like this

Zip::unzip('/backups/today.zip','/a/folder',[
    'password' => 'passw0rd'
]);

Fluent Interface

The ZIP class also provides a fluent interface for working with ZIP archives.

Create a ZIP Archive

To create a new ZIP and files and directories. When you add a directory it will add all files and sub directories recursively.

$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('README.md')
    ->add('src')
    ->save();

Encryption

To encrypt files with passwords you need to be using PHP 7.3 or above.

To encrypt all the files in the archive, call the encrypt method after adding the files, you can optionally supply the encryption method. Supported encryption methods are aes128,aes192 and aes256.

$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('README.md')
    ->add('src')
    ->encrypt('passw0rd')
    ->save();

If just want to encrypt certain files

$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('README.md')
    ->add('Financials.xlsx',['password' => 'secret'])
    ->save();

Compression

If you just want to store a file in the ZIP archive without compression you can set compress to false.

$zip = new Zip();
$zip->create('/path/to/file.zip')
    ->add('logo.jpg',['compress'=>false])
    ->save();

Unzip a ZIP Archive

To extract files from a ZIP file

$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->extract('/destination/folder')

If the ZIP file has encrypted files

$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->extract('/destination/folder',['password'=>'foo']);

You can also extract selected files

$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->extract('/destination/folder',[
        'files'=>[
            'README.md',
            'LICENSE.md'
        ]
    ]);

Listing contents

To list contents of a ZIP file

$zip = new Zip();
$list = $zip->open('/path/to/file.zip')
            ->list();

This will output like this

Array
(
    [0] => Origin\Zip\FileObject Object
        (
            [name] => README.md
            [size] => 666
            [timestamp] => 1576656596
            [compressedSize] => 371
            [encrypted] => 1
        )
)

You can also just list files from within a folder of the ZIP file

$zip = new Zip();
$testFiles = $zip->open('/path/to/file.zip')
                 ->list('tests');

Getting contents of a file

To get the contents of a file

$zip = new Zip();
$contents = $zip->open('/path/to/file.zip')
                 ->get('README.md');

Renaming

To rename a file in a ZIP archive

$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->rename('foo.txt','bar.txt');

Deleting Files

To delete a file from a ZIP archive

$zip = new Zip();
$zip->open('/path/to/file.zip')
    ->delete('tests/ControllerTest.php');

originphp/zip 适用场景与选型建议

originphp/zip 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 765 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「compression」 「zip」 「archive」 「originPHP」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 originphp/zip 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 originphp/zip 我们能提供哪些服务?
定制开发 / 二次开发

基于 originphp/zip 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 765
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-12-20