s3-bucket-stream-zip-php
s3-bucket-stream-zip-php copied to clipboard
Use AWS SDK for PHP v3
Thanks a lot for this class, exactly what I was looking for. However, since I needed to use v3 of the AWS SDK for PHP (due to Laravel and bucket location), I forked it and made a few changes.
This PR updates the library to use the v3 of the SDK, which is required to access S3 buckets which only support modern/more recent ciphers for encryption -- and it makes it compatible to use with e.g. Laravel 5.2.
The following changes were made:
- Use AWS SDK for PHP v3
- Use StyleCI to have a unified code style
- changed the constructor to make it compatible with v3
- include the non-prefix part of the filename in the ZIP which essentially allows for multiple folders in the archive
Thus, this probably warrants a major release according to semver as there are breaking changes.
Taken from the examples/simple.php
, the new constructor looks like this:
$stream = new S3BucketStreamZip([
'key' => 'your-key-goes-here',
'secret' => 'your-secret-goes-here',
'bucket' => 'the-name-of-your-bucket',
'region' => 'the-region-of-your-bucket',
'prefix' => 'prefix-of-the-files-to-zip',
]);
I'm using these changes in a production environment with no issues so far. Let me know if you want me to make any changes!
I just realized the AWS PHP SDK v3 requires PHP >= 5.5. Considerin 7.0 is out now and 5.4 was EOL more than one year ago (even 5.5 is EOL), I think it's safe to drop support for these old versions.
Possible to get this merged soon? Could really use it on a project and as @limenet mentioned even PHP 5.5 is officially EOL.
A new tag of 2.0 could keep the old versions working without issue.
@tomschlick since I'm using this PR in production and haven't heard anything from @jmathai I decided to publish my fork as a standalone package. This, of course, comes with its own risks, however you're welcome to use limenet/s3-bucket-stream-zip-php
in your project.
Only caveat: it's PHP 7.0+ only. Reason being I'm no longer using PHP 5.x and I don't want to publish a package I haven't tested on a version I'm not using.
@limenet thanks! I'll probably do just that. I'm using 7.1 so thats not an issue.
can we get this merged?
Sorry for the delay in replying here. It's been a while since I've worked with composer. Here's what I did and I think it should be sufficient but it would be great if someone can test (I am unable at the moment).
I created v1.0 (current master) and v2.0 (pulled this pr) branches. I also created and pushed the respective v1.0 and v2.0 tags. I believe that's all composer needs. If that's working for you to install v2.0 using composer then I'll go ahead and merge this into master and update the docs.
How to download multiple zips from for-loop call below code closes the window when 1st zip download starts so that remaining loops cant work
i.e. $RowImagesData = array() // in which multiple references are added. $obj =& get_instance(); $obj->load->library('s3_stream'); $obj->load->library('aws_sdk'); $s3_dir= 'images/'; $bucketname= 'XYZ';
foreach ($RowImagesData as $RIKey => $RIValue) { $OrderId = $RIValue['reference'] $path = $s3_dir. $OrderId; $files = $obj->aws_sdk->listObjects(array('Bucket' => $bucketname, 'MaxKeys' => 1000, 'Prefix' => $path))->getPath('Contents'); if(count($files) > 0) { $obj->s3_stream->download($bucketname,$path,$orderid); } else { echo ""; } }