Delete object or bucket in Amazon S3?

In the case you are describing, "photos" is the bucket. S3 does not have sub-buckets or directories. Directories are simulated by using slashes in the object key. "thumbs/file.jpg" is an object key and "thumbs/" would be considered a key prefix.

Dagon's examples are good and use the older version 1.x of the AWS SDK for PHP. However, you can do this more easily with the newest 2.4.x version AWS SDK for PHP which includes a helper method for deleting multiple objects.

<?php

// Include the SDK. This line depends on your installation method.
require 'aws.phar';

use Aws\S3\S3Client;

$s3 = S3Client::factory(array(
    'key'    => 'your-aws-access-key',
    'secret' => 'your-aws-secret-key',
));

// Delete the objects in the "photos" bucket with the a prefix of "thumbs/"
$s3->deleteMatchingObjects('photos', 'thumbs/');

//Include s3.php file first in code

if (!class_exists('S3'))
            require_once('S3.php');
        //AWS access info
        if (!defined('awsAccessKey'))
            define('awsAccessKey', 'awsAccessKey');
        if (!defined('awsSecretKey'))
            define('awsSecretKey', 'awsSecretKey');
        //instantiate the class
        $s3 = new S3(awsAccessKey, awsSecretKey);

  if ($s3->deleteObject("bucketname", `filename`)) {
        echo 'deleted';
}
else
{
echo 'no file found';
}