Omschrijving
The AWS SDK for PHP makes it easy for developers to access 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.
Getting Started
- Sign up for AWS – Before you begin, you need to sign up for an AWS account and retrieve your AWS credentials.
- Minimum requirements – To run the SDK, your system will need to meet the minimum requirements, including having PHP >= 8.1. We highly recommend having it compiled with the cURL extension and cURL 7.16.2+ compiled with a TLS backend (e.g., NSS or OpenSSL).
- 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. If Composer is installed globally on your system, you can run the following in the base directory of your project to add the SDK as a dependency:composer require aws/aws-sdk-php Please see the Installation section of the User Guide for more detailed information about installing the SDK through Composer and other means. - 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.
- Beta: Removing unused services — To date, there are over 300 AWS services available for use with this SDK. You will likely not need them all. If you use Composer and would like to learn more about this feature, please read the linked documentation.
Create an Amazon S3 client
<?php
// Require the Composer autoloader.
require 'vendor/autoload.php';
use AwsS3S3Client;
// Instantiate an Amazon S3 client.
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-west-2'
]);Upload a file to Amazon S3
<?php
// Upload a publicly accessible file. The file size and type are determined by the SDK.
try {
$s3->putObject([
'Bucket' => 'my-bucket',
'Key' => 'my-object',
'Body' => fopen('/path/to/file', 'r'),
'ACL' => 'public-read',
]);
} catch (AwsS3ExceptionS3Exception $e) {
echo "There was an error uploading the file.n";
}Features
- Provides easy-to-use HTTP clients for all supported AWS services, regions, and authentication protocols.
- Is built on Guzzle, and utilizes many of its features, including persistent connections, asynchronous requests, middlewares, etc.
- Provides convenience features including easy result pagination via Paginators, Waiters, and simple Result objects.
- Provides a multipart uploader tool for Amazon S3 and Amazon Glacier that can be paused and resumed.
- Provides an Amazon S3 Stream Wrapper, so that you can use PHP’s native file handling functions to interact with your S3 buckets and objects like a local filesystem.
- Provides an Amazon S3 Encryption Client for creating and interacting with encrypted objects in your S3 buckets.
- Provides the Amazon DynamoDB Session Handler for easily scaling sessions on a fast, NoSQL database.
- Automatically uses IAM Instance Profile Credentials on configured Amazon EC2 instances.