dimabdc / zipstream64
ZipStream是一个库,可以在PHP中动态流式传输大型的动态zip文件,无需在服务器上写入磁盘。
0.3.0.2
2018-03-12 14:23 UTC
Requires
- php: >= 5.6
- php-64bit: *
- psr/http-message: 1.0.1
Requires (Dev)
- phpunit/phpunit: 4.3.*
README
支持64位大文件流的Zip文件
请参阅文件LICENSE.md以获取许可和保修信息(标准MIT许可证)。
安装
最简单的安装方法是通过Composer
"require": { "brokencube/zipstream64": "0.1.*" }
概述
一个快速的简单PHP流式zip文件下载器。以下是一个简单的示例
use brokencube\ZipStream\ZipStream; # Autoload the dependencies require 'vendor/autoload.php'; # create a new zipstream object $zip = new ZipStream('example.zip'); # create a file named 'hello.txt' $zip->addFile('hello.txt', 'This is the contents of hello.txt'); # add a file named 'image.jpg' from a local file 'path/to/image.jpg' $zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg'); # add a file named 'goodbye.txt' from an open stream resource $fp = tmpfile(); fwrite($fp, 'The quick brown fox jumped over the lazy dog.'); $zip->addFileFromStream('goodbye.txt', $fp); fclose($fp); # add a file named 'farewell.txt' from a PSR7 stream (e.g. Guzzle / AWS) $amazonS3 = new Sdk()->createS3(); $file = $amazonS3->getObject(['Bucket' => 'bucket.name', 'Key' => 'path/to/farewell.txt']); $zip->addFileFromPsr7Stream('farewell.txt', $file['Body']); # finish the zip stream $zip->finish();
要求
- 64位PHP版本5.6或更高。
贡献者
此项目非常依赖于以下项目的先前工作
此项目的95%的功劳归功于他们!
一些注意事项
64位zip文件与macOS默认的Zip库(即内置解压缩程序使用的库)不兼容。如果您需要在mac上使用大于4GB的zip文件,用户需要使用第三方软件来解压缩它们。如果您的zip文件小于4GB,可以通过调用来关闭64位支持
$zip = new ZipStream('example.zip', [ZipStream::OPTION_USE_ZIP64 => false]);