CopyingObjectUsingPHP
Copy an Object Using the AWS SDK for PHP
This topic guides you through using classes from version 3 of the AWS SDK for PHP to copy a single object and multiple objects within Amazon S3, from one bucket to another or within the same bucket.
This topic assumes that you are already following the instructions for Using the AWS SDK for PHP and Running PHP Examples and have the AWS SDK for PHP properly installed.
The following tasks guide you through using PHP SDK classes to copy an object that is already stored in Amazon S3.
The following tasks guide you through using PHP classes to make multiple copies of an object within Amazon S3.
Copying Objects
1 | Create an instance of an Amazon S3 client by using the Aws\S3\S3Client class constructor. |
2 | To make multiple copies of an object, you execute a batch of calls to the Amazon S3 client getCommand() method, which is inherited from the Aws\CommandInterface class. You provide the CopyObject command as the first argument and an array containing the source bucket, source key name, target bucket, and target key name as the second argument. |
Example of Copying Objects within Amazon S3
The following PHP example illustrates the use of the copyObject()
method to copy a single object within Amazon S3 and using a batch of calls to CopyObject
using the getcommand()
method to make multiple copies of an object.