PHPackages                             wamland/wam-amazon-s3-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. wamland/wam-amazon-s3-php

ActiveLibrary[File &amp; Storage](/categories/file-storage)

wamland/wam-amazon-s3-php
=========================

This service allows to send and receive a file on Amazon S3

248PHP

Since Jun 27Pushed 8y ago4 watchersCompare

[ Source](https://github.com/wamland-team/wam-s3-php)[ Packagist](https://packagist.org/packages/wamland/wam-amazon-s3-php)[ RSS](/packages/wamland-wam-amazon-s3-php/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Wamland Amazon S3 PHP
=====================

[](#wamland-amazon-s3-php)

This service allows to send and receive a file on Amazon S3

#### Recovering sources

[](#recovering-sources)

```
composer require wamland/wam-amazon-s3-php:dev-master

```

#### Creation of the file containing the environment variables

[](#creation-of-the-file-containing-the-environment-variables)

```
cp vendor/wamland/wam-amazon-s3-php/.env_sample.php .env.php
vim .env.sh

```

#### Default configuration

[](#default-configuration)

```
// AWS S3
define('AWS_ACL', 'public-read');
define('AWS_VERSION', 'latest');
define('AWS_REGION', 'ap-southeast-2');

define('AWS_ACCESS_KEY_ID', '');
define('AWS_SECRET_ACCESS_KEY', '');
define('AWS_BUCKET', '');

```

#### Loading libraries

[](#loading-libraries)

```
require('.env.php');
require('vendor/autoload.php');

```

#### Initializing the Amazon S3 Connector

[](#initializing-the-amazon-s3-connector)

```
use App\Services\S3Service;

$s3 = new S3Service(
    AWS_REGION,
    AWS_VERSION,
    AWS_ACCESS_KEY_ID,
    AWS_SECRET_ACCESS_KEY
);

$s3->bucket = AWS_BUCKET;

```

#### Uploading a media

[](#uploading-a-media)

```
$s3->file = 'src/resources/assets/fixtures/pic.jpg';
$s3->key = 'pic.jpg'; // If the key is not set, the file name will be used

try {
    $s3->put();
} catch (\Exception $e) {
    echo $e->getMessage();
    die();
}

```

#### Retrieving a media

[](#retrieving-a-media)

```
$s3->key = 'src/resources/assets/fixtures/pic.jpg';

try {
    $media = $s3->get();
} catch (\Exception $e) {
    echo $e->getMessage();
    die();
}

```

#### Deleting an item

[](#deleting-an-item)

```
try {
    $s3->delete();
} catch (\Exception $e) {
    echo $e->getMessage();
    die();
}

```

### Unit test ([Kahlan](https://kahlan.github.io/))

[](#unit-test-kahlan)

```
composer test

```

Complete sending and receiving example
--------------------------------------

[](#complete-sending-and-receiving-example)

```
