'us-west-2', 'version' => '2006-03-01' ]); // Gets the access control list (ACL) of an object. $bucket = 'my-s3-bucket'; $key = 'my-object'; try { $resp = $s3Client->getObjectAcl([ 'Bucket' => $bucket, 'Key' => $key, ]); echo "Succeed in retrieving object ACL as follows: \n"; var_dump($resp); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; } // Use acl subresource to set the access control list (ACL) permissions // for an object that already exists in a bucket $params = [ 'ACL' => 'public-read', 'AccessControlPolicy' => [ // Information can be retrieved from `getObjectAcl` response 'Grants' => [ [ 'Grantee' => [ 'DisplayName' => '', 'EmailAddress' => '', 'ID' => '', 'Type' => 'CanonicalUser', 'URI' => '', ], 'Permission' => 'FULL_CONTROL', ], // ... ], 'Owner' => [ 'DisplayName' => '', 'ID' => '', ], ], 'Bucket' => $bucket, 'Key' => $key, ]; try { $resp = $s3Client->putObjectAcl($params); echo "Succeed in setting object ACL.\n"; } catch (AwsException $e) { // Display error message echo $e->getMessage(); echo "\n"; } // snippet-end:[s3.php.object_acl.main] // snippet-end:[s3.php.object_acl.complete] // snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.] // snippet-sourcedescription:[s3ObjectAcl.php demonstrates how to set access control list (ACL) permissions for a file (or object) in an Amazon S3 bucket.] // snippet-keyword:[PHP] // snippet-sourcesyntax:[php] // snippet-keyword:[AWS SDK for PHP v3] // snippet-keyword:[Code Sample] // snippet-keyword:[Amazon S3] // snippet-service:[s3] // snippet-sourcetype:[full-example] // snippet-sourcedate:[2018-09-20] // snippet-sourceauthor:[jschwarzwalder (AWS)]