zip stream
1.0.0
이 라이브러리는 메모리 발자국이 낮은 대형 지퍼 파일을 생성하기위한 것입니다. ZIP 파일의 내용은 메모리에 한 번에 저장되지 않습니다. 모든 것은 스트림을 사용하여 작성됩니다. 이 라이브러리는 Zip 파일 만 작성하기위한 것이며 읽기 기능이 없습니다.
MIT 라이센스
유일한 요구 사항은 PHP 7.0+ 및 Zlib 확장 (거의 항상 활성화)입니다.
composer require jdwil/zip-stream
./vendor/bin/phpspec run
$zipStream = ZipStream::forFile('/path/to/file.zip');
// Add a file from disk
$zipStream->addFileFromDisk('foo.txt', '/path/to/foo.txt');
// Add a file from a stream
$stream = ReadStream::forFile('/path/to/bar.txt');
$zipStream->addFileFromStream('bar.txt', $stream);
// Add arbirary data
$zipStream->addFile('baz.txt', 'some arbitrary text');
// Always close the Zip Stream
$zipStream->close();
$zipStream = ZipStream::forFile('/path/to/file.zip');
$zipStream->beginFile('foo.txt');
while ($data = $somePdoStatement->fetch()) {
$zipStream->addFilePart(implode(',', $data));
}
$zipStream->endFile();
$zipStream->close();
파일이 빌드 될 때 전송되므로 다운로드는 사용자를 위해 즉시 시작됩니다.
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="foo.zip"');
header('Content-Transfer-Encoding: binary');
$zipStream = ZipStream::forFile('php://output');
// Build your zip file
$zipStream->close();
JD Williams [email protected]