Filebase
Search…
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.
This guide was written using Ubuntu 20.04 and tested using the command line interface. If you are using an Integrated Development Environment (IDE), the installation of dependencies and modules will vary.

Prerequisites:

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:
  • key: Your Filebase Access Key
  • secret: Your Filebase Secret Key
  • bucket: Filebase bucket name
  • key: Object name
  • file_path: File path to the object
1
<?php
2
3
use Aws\\S3\\Exception\\S3Exception;
4
use Aws\\S3\\S3Client;
5
6
// Load SDK by requiring from your composer vendor directory
7
require 'vendor/autoload.php';
8
9
// use the following code to use filebase credentials.
10
$raw_credentials = array(
11
12
'credentials' => [
13
'key' => 'filebase-access-key',
14
'secret' => 'filebase-secret-key'
15
16
],
17
18
'endpoint' => 'https://s3.filebase.com',
19
'region' => 'us-east-1',
20
'version' => 'latest',
21
'use_path_style_endpoint' => true
22
23
);
24
25
//use the following code to establish a connection to Filebase via access and secret keys.
26
$s3 = S3Client::factory($raw_credentials);
27
$bucket = "filebase-bucket";
28
$key = "object-name";
29
$file_Path = "/path/to/object";
30
31
try {
32
$result = $s3->putObject([
33
'Bucket' => $bucket,
34
'Key' => $key,
35
'SourceFile' => $file_Path]);
36
37
} catch (S3Exception $e) {
38
echo $e->getMessage() . PHP_EOL;
39
}
Copied!

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:
  • key: Your Filebase Access Key
  • secret: Your Filebase Secret Key
  • bucket: Filebase bucket name
  • key: Object name
  • save_path: File path to save the object
1
<?php
2
3
use Aws\\S3\\Exception\\S3Exception;
4
use Aws\\S3\\S3Client;
5
6
// Load SDK by requiring from your composer vendor directory
7
require 'vendor/autoload.php';
8
9
// use the following code to use filebase credentials.
10
$raw_credentials = array(
11
'credentials' => [
12
'key' => 'filebase-access-key',
13
'secret' => 'filebase-secret-key'
14
],
15
16
'endpoint' => 'https://s3.filebase.com',
17
'region' => 'us-east-1',
18
'version' => 'latest',
19
'use_path_style_endpoint' => true
20
21
);
22
23
//use the following code to establish a connection to Filebase via access and secret keys.
24
25
$s3 = S3Client::factory($raw_credentials);
26
$bucket = "filebase-bucket";
27
$key = "object-name";
28
$save_Path = "/path/to/save/object";
29
30
try {
31
$result = $s3->getObject([
32
'Bucket' => $bucket,
33
'Key' => $key]);
34
} catch (S3Exception $e) {
35
echo $e->getMessage() . PHP_EOL;
36
}
Copied!

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:
  • key: Your Filebase Access Key
  • secret: Your Filebase Secret Key
  • bucket: Filebase bucket name
  • key: Object name
1
<?php
2
3
use Aws\\S3\\Exception\\S3Exception;
4
use Aws\\S3\\S3Client;
5
6
// Load SDK by requiring from your composer vendor directory
7
require 'vendor/autoload.php';
8
9
// use the following code to use filebase credentials.
10
$raw_credentials = array(
11
'credentials' => [
12
'key' => 'filebase-access-key',
13
'secret' => 'filebase-secret-key'
14
],
15
16
'endpoint' => 'https://s3.filebase.com',
17
'region' => 'us-east-1',
18
'version' => 'latest',
19
'use_path_style_endpoint' => true
20
);
21
22
//use the following code to establish a connection to Filebase via access and secret keys.
23
24
$s3 = S3Client::factory($raw_credentials);
25
$bucket = "filebase-bucket";
26
$key = "object-name";
27
28
try {
29
$result = $s3->deleteObject([
30
'Bucket' => $bucket,
31
'Key' => $key]);
32
} catch (S3Exception $e) {
33
echo $e->getMessage() . PHP_EOL;
34
}
Copied!
For more information on the AWS SDK for PHP, check out the documentation here.
If you have any questions, please send us an email at [email protected].
Last modified 1mo ago