PHP: How to sync data between s3 buckets using php code without using the CLI .?

半城伤御伤魂 提交于 2019-12-10 11:44:56

问题


I can't seem to find sync and copy options in the php sdk for amazon-s3. Currently I am using aws s3 cp/sync CLI command from within PHP code to achieve this which doesn't seem very neat to me. Any ideas?


回答1:


You can do this with a combination of two features in the PHP SDK.

First, checkout the S3Client::uploadDirectory() method (see user guide). You can upload a while directory's contents like this:

$s3Client->uploadDirectory('/local/directory', 'your-bucket-name');

If you combine this with the S3 Stream Wrapper, then instead of using a local directory as the source, you can specify a bucket.

$s3Client->registerStreamWrapper();
$s3Client->uploadDirectory('s3://your-other-bucket-name', 'your-bucket-name');

This is pretty powerful, because you can even do something across regions if you use a differently configured S3Client object for the Stream Wrapper than the one doing the uploadDirectory().



来源:https://stackoverflow.com/questions/21797528/php-how-to-sync-data-between-s3-buckets-using-php-code-without-using-the-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!