PHPackages                             dnx/php-s3 - 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. dnx/php-s3

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

dnx/php-s3
==========

Manage S3 Files using AWS SDK for PHP

0.0.2(5y ago)0606MITPHPPHP &gt;=7.1

Since Dec 15Pushed 5y ago2 watchersCompare

[ Source](https://github.com/DNXLabs/php-s3)[ Packagist](https://packagist.org/packages/dnx/php-s3)[ RSS](/packages/dnx-php-s3/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

S3 Provider ☁️
==============

[](#s3-provider-️)

This library provides a S3 Management.

Installation
============

[](#installation)

```
composer require dnx/php-s3
```

Usage
=====

[](#usage)

List Bucket
-----------

[](#list-bucket)

`listObjects($bucket, $path = null)`

```

Required
    $bucket: Bucket name

Optional:
    $path: File path (if null will list all from s3 root)

Return 2D array e.g.:
    $res->list => [
        'folder1'           => [$files],
        'folder1/folder3'   => [$files],
        'folder2'           => [$files]
    ]

```

Get File
--------

[](#get-file)

`getObject($bucket, $filePath)`

```

Required:
    $bucket: Bucket name
    $filePath:
        File path (if empty will look bucket root) + / +
        File name including extension (image.png)

Return: To download the item, use the `StreamedResponse()` example
        To manipulate the object body, just return `(string)$object->file['Body']`

```

Get Cloud Front URL
-------------------

[](#get-cloud-front-url)

`getCloudFrontURL($bucket, $filePath)`

```
Required:
    $bucket: Bucket name
    $filePath:
        File path (if empty will look bucket root) + / +
        File name including extension (image.png)

Return: success: The CloudFront URL for the informed bucket and file
        return [ 'code' => 200, 'response' => 'success', 'message' => $url ]

        error: If Cloud Front Distribution not found, it will throw an Exception
        throw new Exception('CloudFront Distribution Not Found');

```

Upload Files
------------

[](#upload-files)

`uploadObjects($bucket, $files)`

```

Required:
    $bucket: Bucket name
    $files:  File list following the pattern
             [ 'Key' => 'file path' + 'file name.extension', 'Body' => 'file body' ]

Return:
    success: [ 'response' => 'success', 'message' => 'Files Uploaded!', 'results' => $results];
    warning: [ 'response' => 'warning', 'message' => 'Not All Files Uploaded!', 'succeeded' => $succeeded, 'failed' => $failed ];

```

Delete File
-----------

[](#delete-file)

`deleteObject($bucket, $filePath)`

```

Required:
    $bucket: Bucket name
    $filePath:
        File path (if empty will look bucket root) + / +
        File name including extension (image.png)

Return:
    success: [ 'response' => 'success', 'message' => $message ];
    error:   throw new Exception($message);

```

Detailed example of usage
-------------------------

[](#detailed-example-of-usage)

```
use DNX\S3\CreateItem;
use DNX\S3\ReadItem;
use DNX\S3\DeleteItem;

use Aws\Credentials\CredentialProvider;
use Aws\S3\Exception\S3Exception;
use \Exception;
use Log;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function __construct(){}

    public function listObjects(Request $request)
    {
        try {
            $query  = (object)$request->all();
            // Region required, if code not found, will set to sydney
            // CredentialProvider is optional, we recommend to use user roles and do not use credentials
            $readS3 = new ReadItem('ap-southeast-2', CredentialProvider::env());
            $res    = $readS3->listObjects($query->bucket, $query->path);
            return view('s3.list', [ 'list' => $res->list, 'bucket' => $bucket]);
        } catch(S3Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getAwsErrorMessage(), 'code' => $e->getStatusCode() ];
        } catch(Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getMessage() ];
        }
    }

    public function getObject(Request $request)
    {
        try {
            $query  = (object)$request->all();
            // CredentialProvider is optional, we recommend to use user roles and do not use credentials
            $readS3 = new ReadItem('ap-southeast-2', CredentialProvider::env());
            $object = $readS3->getObject($query->bucket, $query->filePath);
            $headers = [
                'Content-Type'        => $object->file['ContentType'],
                'Content-Disposition' => 'attachment; filename=' . $query->file
            ];
            $stream = function () use ($object) {
                echo $object->file['Body'];
            };
            return new StreamedResponse($stream, 200, $headers);    // If you want to download it
            // return (string)$object->file['Body'];                // If you want to manipulate file body
        } catch(S3Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getAwsErrorMessage(), 'code' => $e->getStatusCode() ];
        } catch(Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getMessage() ];
        }
    }

    public function getCloudFrontURL(Request $request)
    {
        try {
            $query      = (object)$request->all();
            // CredentialProvider is optional, we recommend to use user roles and do not use credentials
            $readS3     = new ReadItem('ap-southeast-2', CredentialProvider::env());
            $url        = $readS3->getCloudFrontURL($query->bucket, $query->filePath);
            return $url;
        } catch(S3Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getAwsErrorMessage(), 'code' => $e->getStatusCode() ];
        } catch(Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getMessage() ];
        }
    }

    public function uploadObjects(Request $request)
    {
        // https://docs.aws.amazon.com/aws-sdk-php/v2/guide/feature-commands.html#executing-commands-in-parallel
        // Without ContentType parameter the file will be downloaded instead of served
        try {
            $query      = (object)$request->all();
            $files      = [];
            foreach ($query->files as $key => $file ) {
                $key = (isset($query->path) ? $query->path . "/" : "") . $file->getClientOriginalName();
                array_push($files, [
                    'Key'           => $key,
                    'Body'          => $file->get(),
                    'ContentType'   => $file->getClientMimeType()
                ]);
            }
            // CredentialProvider is optional, we recommend to use user roles and do not use credentials
            $createS3   = new CreateItem('ap-southeast-2', CredentialProvider::env());
            $res        = $createS3->uploadObjects($query->bucket, $files);
            foreach($res->results as $index => $result)
            {
                if($result instanceof Exception) {
                    $message   = $result->getMessage();
                    Log::error("Error on creating file: {$message}");
                } else {
                    // Database persist for each file here
                    Log::info("Creating file completed");
                }
            }
            return $res;
        } catch (Exception $e) {
            $message   = $e->getMessage();
            Log::error("S3Client Bulk Load Error: {$message}");
        }
    }

    public function deleteObject(Request $request)
    {
        try {
            $query      = (object)$request->all();
            // CredentialProvider is optional, we recommend to use user roles and do not use credentials
            $deleteS3   = new DeleteItem('ap-southeast-2', CredentialProvider::env());
            $res        = $deleteS3->deleteObject($query->bucket, $query->filePath);
            return $res;
        } catch(S3Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getAwsErrorMessage(), 'code' => $e->getStatusCode() ];
        } catch(Exception $e) {
            return [ 'response' => 'error', 'message' => $e->getMessage() ];
        }
    }
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1979d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a589f58fee5c5a2d6eed46eb22d6ce11630b6baeef2d2cb7acaebdb30ea2023?d=identicon)[dnxlabs](/maintainers/dnxlabs)

---

Top Contributors

[![DaisyMonte](https://avatars.githubusercontent.com/u/8137213?v=4)](https://github.com/DaisyMonte "DaisyMonte (7 commits)")

---

Tags

phplaravels3aws

### Embed Badge

![Health badge](/badges/dnx-php-s3/health.svg)

```
[![Health](https://phpackages.com/badges/dnx-php-s3/health.svg)](https://phpackages.com/packages/dnx-php-s3)
```

###  Alternatives

[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)[jmathai/s3-bucket-stream-zip-php

PHP library to efficiently stream contents from an AWS S3 bucket or folder as a zip file

56114.4k](/packages/jmathai-s3-bucket-stream-zip-php)[unisharp/s3-presigned

An AWS S3 package for pre-signed upload purpose in Laravel and PHP.

141.8k](/packages/unisharp-s3-presigned)[juhasev/laravelcdn

Content Delivery Network (CDN) Package for Laravel

1820.4k](/packages/juhasev-laravelcdn)[kolay/xlsx-stream

High-performance XLSX streaming writer for Laravel with zero disk I/O and direct S3 support

383.0k](/packages/kolay-xlsx-stream)[matecat/simple-s3

Simple S3 Client

1415.0k](/packages/matecat-simple-s3)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
