PHP code example of stechstudio / laravel-zipstream
1. Go to this page and download the library: Download stechstudio/laravel-zipstream library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stechstudio / laravel-zipstream example snippets
composer
use STS\ZipStream\Facades\Zip;
class ZipController {
public function build()
{
return Zip::create("package.zip", [
"/path/to/Some File.pdf",
"/path/to/Export.xlsx"
]);
}
}
Zip::create("package.zip", [
// Will be stored as `Some File.pdf` in the zip
"/path/to/Some File.pdf",
// Will be stored as `Export.xlsx` in the zip
"/path/to/data.xlsx" => 'Export.xlsx',
// Will create a `log` subfolder in the zip and be stored as `log/details.txt`
"/path/to/log.txt" => "log/details.txt"
]);
use STS\ZipStream\Models\S3File;
// Create your own client however necessary
$s3 = new Aws\S3\S3Client();
Zip::create("package.zip")->add(
S3File::make("s3://bucket-name/path/to/object.pdf")->setS3Client($s3)
);
use STS\ZipStream\Models\File;
// Retrieve file records from the database
$files = ...;
$zip = Zip::create("package.zip");
foreach($files AS $file) {
$zip->add(
File::make($file->path, $file->name)->setFilesize($file->size)
);
}