title: Copying an object from one Amazon S3 bucket to another using PHP
body: <p>I'm trying to copy a folder from one S3 bucket to another using PHP but it is causing me problems. I can create the folder I want but I cannot copy from one folder to another. Here is my code. Any help would be greatly appreciated</p>
  
  <pre><code>$key = '123';
  $secret = '123';
  
  $bucket = 'bck-users';
  $keyname = $username;
  
  try {
              //Create bucket for user
              $s3 = Aws\S3\S3Client::factory(array(
              'region' =&gt; 'eu-west-1',
              'version' =&gt; '2006-03-01',
              'credentials' =&gt; array(
                'key' =&gt; $key,
                'secret' =&gt; $secret,
                  )
              ));
  
              $result = $s3-&gt;putObject(array(
                'Bucket' =&gt; $bucket,
                'Key'    =&gt; $keyname,
              ));
  
              echo $result['ObjectURL'] . "\n";
  
          }
          catch (Exception $e){
            echo $e-&gt;getMessage() . "\n";
          }
  
          //Copy default files to bucket
          $sourceBucket = 'bck-users';
          $sourceKeyname = 'default';
          $targetBucket = $username;
          $targetKeyname = 'default';             
  
          // Instantiate the client.
          $s3 = S3Client::factory(array(
              'region' =&gt; 'eu-west-1',
              'version' =&gt; '2006-03-01',
              'credentials' =&gt; array(
                'key' =&gt; $key,
                'secret' =&gt; $secret,);
  
          // Perform a batch of CopyObject operations.
          $batch = array();
          $batch[] = $s3-&gt;getCommand('CopyObject', array(
                  'Bucket'     =&gt; $targetBucket,
                  'Key'        =&gt; $targetKeyname,
                  'CopySource' =&gt; $sourceBucket/$sourceKeyname,
              ));
          }
          try {
              $successful = $s3-&gt;execute($batch);
          } 
          catch (Exception $e){
            echo $e-&gt;getMessage() . "\n";
          }
  </code></pre>