BBnepal-Accounts/vendor/maennchen/zipstream-php/guides/StreamOutput.rst

40 lines
824 B
ReStructuredText
Raw Normal View History

2024-07-10 12:43:19 +00:00
Stream Output
===============
Stream to S3 Bucket
---------------
.. code-block:: php
2024-09-29 11:14:27 +00:00
2024-07-10 12:43:19 +00:00
use Aws\S3\S3Client;
use Aws\Credentials\CredentialProvider;
use ZipStream\ZipStream;
$bucket = 'your bucket name';
$client = new S3Client([
'region' => 'your region',
'version' => 'latest',
'bucketName' => $bucket,
'credentials' => CredentialProvider::defaultProvider(),
]);
$client->registerStreamWrapper();
$zipFile = fopen("s3://$bucket/example.zip", 'w');
2024-09-29 11:14:27 +00:00
$zip = new ZipStream(
enableZip64: false,
outputStream: $zipFile,
);
2024-07-10 12:43:19 +00:00
2024-09-29 11:14:27 +00:00
$zip->addFile(
fileName: 'file1.txt',
data: 'File1 data',
);
$zip->addFile(
fileName: 'file2.txt',
data: 'File2 data',
);
2024-07-10 12:43:19 +00:00
$zip->finish();
2024-09-29 11:14:27 +00:00
fclose($zipFile);