Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)

Deleting an Object Using the AWS SDK for PHP

This topic shows how to use classes from version 3 of the AWS SDK for PHP to delete an object from a non-versioned bucket. For information on deleting an object from a versioned bucket, see Deleting an Object Using the REST API.

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 PHP example deletes an object from a bucket. Because this example shows how to delete objects from non-versioned buckets, it provides only the bucket name and object key (not a version ID) in the delete request. . For information about running the PHP examples in this guide, see Running PHP Examples.

<?php require 'vendor/autoload.php'; use Aws\S3\S3Client; $bucket = '*** Your Bucket Name ***'; $keyname = '*** Your Object Key ***'; $s3 = new S3Client([ 'version' => 'latest', 'region' => 'us-east-1' ]); // Delete an object from the bucket. $s3->deleteObject([ 'Bucket' => $bucket, 'Key' => $keyname ]);

Related Resources

On this page: