Skip to content

aws/aws-sdk-php

 
 

Repository files navigation

AWS SDK for PHP

@awsforphp on Twitter Total Downloads Build Status Apache 2 License Code Climate ![Gitter](https://badges.gitter.im/Join Chat.svg)

The AWS SDK for PHP enables PHP developers to use Amazon Web Services in their PHP code, and build robust applications and software using services like Amazon S3, Amazon DynamoDB, Amazon Glacier, etc. You can get started in minutes by installing the SDK through Composer or by downloading a single zip or phar file from our latest release.

Deprecation Notice - S3 Signature V2

S3 support for Signature V2 is being deprecated, after which only Signature V4 will be supported. Users of V2 of the PHP SDK will have to upgrade to version 2.5 or later in order to continue using S3. It is recommended to upgrade to version 3 of the SDK, which uses Signature V4 as a default, if possible. To use Signature V4 with version 2.5+ of the SDK, you can specify signature as a configuration option, as in the following example.

    $client = S3Client::factory([
        'region' => 'us-east-2',
        'version' => 'latest',
        'signature' => 'v4'
    ]);

Resources

Features

Getting Started

  1. Sign up for AWS – Before you begin, you need to sign up for an AWS account and retrieve your AWS credentials.
  2. Minimum requirements – To run the SDK, your system will need to meet the minimum requirements, including having PHP 5.3.3+ compiled with the cURL extension and cURL 7.16.2+ compiled with OpenSSL and zlib.
  3. Install the SDK – Using Composer is the recommended way to install the AWS SDK for PHP. The SDK is available via Packagist under the aws/aws-sdk-php package. Please see the Installation section of the User Guide for more detailed information about installing the SDK through Composer and other means.
  4. Using the SDK – The best way to become familiar with how to use the SDK is to read the User Guide. The Getting Started Guide will help you become familiar with the basic concepts, and there are also specific guides for each of the supported services.

Quick Example

Upload a File to Amazon S3

<?php
require 'vendor/autoload.php';

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;

// Instantiate an S3 client
$s3 = S3Client::factory();

// Upload a publicly accessible file. The file size, file type, and MD5 hash
// are automatically calculated by the SDK.
try {
    $s3->putObject(array(
        'Bucket' => 'my-bucket',
        'Key'    => 'my-object',
        'Body'   => fopen('/path/to/file', 'r'),
        'ACL'    => 'public-read',
    ));
} catch (S3Exception $e) {
    echo "There was an error uploading the file.\n";
}

You can also use the even easier upload() method, which will automatically do either single or multipart uploads, as needed.

try {
    $resource = fopen('/path/to/file', 'r');
    $s3->upload('my-bucket', 'my-object', $resource, 'public-read');
} catch (S3Exception $e) {
    echo "There was an error uploading the file.\n";
}

More Examples

Related Projects