AWS SDK - PHP
Learn how to use the AWS SDK for PHP with Filebase.
What is AWS SDK - PHP?
AWS SDKs (software development kits) help simplify coding and application development by supporting and providing code objects for use with S3-compatible services. There are a variety of different AWS SDKs, each for a different coding language. This guide covers AWS SDK - PHP. Read below to learn how to use the AWS SDK for PHP with Filebase.
Setting Your Filebase Credentials as Environment Variables
Linux / Mac OS x:
export FILEBASE_ACCESS_KEY_ID=[Filebase-Access-Key]
export FILEBASE_SECRET_ACCESS_KEY=[Filebase-Secret-Key]
Windows:
SET FILEBASE_ACCESS_KEY_ID=[Filebase-Access-Key]
SET FILEBASE_SECRET_ACCESS_KEY=[Filebase-Secret-Key]
Alternatively, you may use the credentials stored in your .aws/credentials file and reference them using 'profile' => 'filebase' in place of the 'credentials' array, or you may hard code your credentials. Hard coding is not recommended for production environments.
List All Buckets
The following code example lists all buckets within a user account.
Upload an Object
The following code example uploads an object to the specified bucket. Replace the following values in the code to match your configuration:
bucket: Filebase bucket name
key: Object name
source: File path to the object
Download an Object
The following code example downloads an object from the specified bucket. Replace the following values in the code to match your configuration:
bucket: Filebase bucket name
key: Object name
List All Objects In a Bucket
The following code example lists all objects from the specified bucket. Replace the following values in the code to match your configuration:
bucket: Filebase bucket name
key: Object name
Delete an Object
The following code example deletes an object from the specified bucket. Replace the following values in the code to match your configuration:
bucket: Filebase bucket name
key: Object name
Generating a Pre-Signed URL
The following code example generates a pre-signed URL for an object in a Filebase bucket. For more information on pre-signed URLs, please see here. This workflow can be used for both public and private buckets. Replace the following values in the code to match your configuration:
bucket: Filebase bucket name
key: Object name
For more information on the AWS SDK for PHP, check out the documentation here, or view additional code examples here.
Last updated
Was this helpful?