Skip to content

Commit

Permalink
Update usage for maennchen/zipstream-php
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Nov 4, 2023
1 parent 5f88426 commit a41d619
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,28 @@ composer require maennchen/zipstream-php
Creating and sending a ZIP file (only in-memory) to the browser:

```php
use ZipStream\Option\Archive;
use ZipStream\ZipStream;

// ...

// Create ZIP file, only in-memory
$archive = new Archive();
$archive->setOutputStream(fopen('php://memory', 'r+'));
$stream = fopen('php://memory', 'w+b');

$zip = new ZipStream(
outputStream: $stream,
// disable output of HTTP headers
sendHttpHeaders: false,
);

// create a file named 'hello.txt'
$zip->addFile(
fileName: 'hello.txt',
data: 'This is the contents of hello.txt',
);

// Add files to ZIP file
$zip = new ZipStream(null, $archive);
$zip->addFile('test.txt', 'my file content');
$zip->finish();

$response = $zipResponder->withZipStream($response, $archive->getOutputStream(), 'download.zip');
$response = $zipResponder->withZipStream($response, $stream, 'download.zip');
```

Sending a zipstream on the fly:
Expand Down

0 comments on commit a41d619

Please sign in to comment.