PHPackages                             isaacongoma/spaces-api - 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. isaacongoma/spaces-api

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

isaacongoma/spaces-api
======================

An API wrapper for DigitalOcean's Spaces object storage designed for easy use

v2(5y ago)110MITPHPPHP &gt;=5.4.0

Since Jun 4Pushed 4y agoCompare

[ Source](https://github.com/isaacongoma/Spaces-API)[ Packagist](https://packagist.org/packages/isaacongoma/spaces-api)[ RSS](/packages/isaacongoma-spaces-api/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

[![Spaces-API](https://camo.githubusercontent.com/f2392b5125dc9c867a6c72c5aa5d965737ab917e823687e9c2c8f0e9dd9e5c19/68747470733a2f2f692e696d6775722e636f6d2f6a37304a7655632e706e67 "Devang Srivastava's Spaces-API")](https://camo.githubusercontent.com/f2392b5125dc9c867a6c72c5aa5d965737ab917e823687e9c2c8f0e9dd9e5c19/68747470733a2f2f692e696d6775722e636f6d2f6a37304a7655632e706e67)

Makes using DigitalOcean's Spaces object storage super easy.

- Makes everything super simple.
- Automatically handles multipart &amp; stream uploads for large files.
- Uses Spaces terminology for objects instead of S3.

Example
=======

[](#example)

Create a Space &amp; upload, it's as easy as that.

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Upload some text.
$my_space->upload("Super cool content", "example.txt");

//Uploaded!
```

### tl;dr

[](#tldr)

- Files

    - [Uploading a file](#upload-a-stored-file)
    - [Uploading text](#upload-text-directly)
    - [Uploading an entire folder](#upload-a-local-folder)
    - [Downloading a file](#download-a-file)
    - [Downloading your entire Space](#download-your-space-to-a-local-folder)
    - [Copy a Space file](#copy-a-file-inside-your-space)
    - [List all files](#list-all-files-inside-your-space)
    - [Check if file exists](#check-whether-a-file-exists)
    - [Retrieve file info](#get-info-on-a-file)
    - [Create signed temporary sharing URL](#create-a-signed-url-used-for-sharing-private-files)
    - [Retrieve public file URL](#create-an-unsigned-url-used-for-sharing-public-files)
    - [Change a file's privacy](#change-a-files-privacy-public--private-acl)
    - [Delete a file](#delete-a-file)
    - [Delete an entire folder](#delete-an-entire-folder)
- Spaces

    - [Create a new Space](#create-a-new-space)
    - [Use an existing Space](#use-an-existing-space)
    - [List all Spaces](#list-all-spaces)
    - [Change your Space's privacy](#change-your-spaces-privacy-acl)
    - [List your Space's CORS rules](#list-your-spaces-cors-rules)
    - [Change your Space's CORS rules](#set-your-spaces-cors-rules)
    - [Destroy your Space](#destroy-your-space)

Installing Spaces-API
=====================

[](#installing-spaces-api)

There are two ways to install Spaces-API. You can either download the project &amp; put it directly in your code's folder, or you can use [Composer](https://getcomposer.org).

### a) The Manual Method

[](#a-the-manual-method)

1. [Download Spaces-API](https://github.com/SociallyDev/Spaces-API/archive/master.zip) &amp; place it in your project.
2. Load it from your code:

```
require_once("spaces.php");
```

### b) The Composer Method

[](#b-the-composer-method)

1. Make sure you have [Composer](https://getcomposer.org).
2. Install Spaces-API:

```
composer require sociallydev/spaces-api:v2

```

3. Make sure your code has the Composer autoloader:

```
require_once("vendor/autoload.php");
```

Setup
-----

[](#setup)

You'll need a DigitalOcean account &amp; API keys to use Spaces-API. You should be able to generate a pair of keys from the [DigitalOcean Dashboard](https://cloud.digitalocean.com/account/api/tokens). In the API page, there should be a section with the title "Spaces access keys". Click "Generate New Key" &amp; follow the steps. That'll give you an access key &amp; a secret key.

We'll be using these keys to initiate a Spaces instance:

```
$spaces = Spaces("ACCESS KEY", "SECRET KEY");
```

Usage
-----

[](#usage)

Once you have a Spaces instance, you can do pretty much anything the Spaces API allows.

Here is an example of downloading all your files to a local directory:

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Download entire Space to a directory.
$my_space->downloadToDirectory("local_backup");
```

[![Spaces-API](https://camo.githubusercontent.com/9ec4d87f207d153ae5e4005d0b5315ecc4edb2336af33f12b497c65ca896039a/68747470733a2f2f692e696d6775722e636f6d2f704837517174502e706e67 "Spaces-API API Reference")](https://camo.githubusercontent.com/9ec4d87f207d153ae5e4005d0b5315ecc4edb2336af33f12b497c65ca896039a/68747470733a2f2f692e696d6775722e636f6d2f704837517174502e706e67)

Top-Level Spaces Functions
==========================

[](#top-level-spaces-functions)

These are all the functions a Spaces instance can perform.

Create a new Space
------------------

[](#create-a-new-space)

```
$spaces = Spaces("ACCESS KEY", "SECRET KEY");

//Creates a new Space.
$spaces->create("my-new-space", "nyc3", "private");
```

- The third (Space privacy) argument is optional. Defaults to private.
- Returns a new single Space instance. Same as `$spaces->space("my-new-space")`.

Use an existing Space
---------------------

[](#use-an-existing-space)

```
$spaces = Spaces("ACCESS KEY", "SECRET KEY");

//Get an existing Space.
$my_space = $spaces->space("my-space", "nyc3");
```

List all Spaces
---------------

[](#list-all-spaces)

```
$spaces = Spaces("ACCESS KEY", "SECRET KEY");

//Returns an array of all available Spaces.
$spaces->listSpaces();
```

---

Single Space Functions
======================

[](#single-space-functions)

These are all the functions a Space instance (From `$spaces->space("my-new-space")`) can perform!

Upload a stored file
--------------------

[](#upload-a-stored-file)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Upload a local stored file.
$my_space->uploadFile("path/to/my/file.txt", "path/on/space.txt", "private");
```

- The second (Save as) argument is optional. Spaces-API attempts to use the original file path as the path on your Space if no save as path is provided.
- The third argument (File privacy) is optional. It defaults to private.
- Returns available info on the file.

Upload text directly
--------------------

[](#upload-text-directly)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Upload a local stored file.
$my_space->upload("my content", "path/on/space.txt", "private");
```

- The first argument (Content) can be a string, but it can also be a StreamInterface or PHP stream resource.
- The third argument (File privacy) is optional. It defaults to private.
- Returns available info on the file.

Upload a local folder
---------------------

[](#upload-a-local-folder)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Uploads an entire local directory.
$my_space->uploadDirectory("my-local-folder");
```

- You can provide a second argument which can be a folder inside your Space where to upload all the files inside the local folder.

Download a file
---------------

[](#download-a-file)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns the file content as result.
$content = $my_space->downloadFile("my-file.txt");

//Saves the file content to the local path, and returns file info.
$info = $my_space->downloadFile("my-file.txt", "save-path/file.txt");
```

Download your Space to a local folder
-------------------------------------

[](#download-your-space-to-a-local-folder)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Uploads an entire local directory.
$my_space->downloadToDirectory("my-local-folder");
```

- You can provide a second argument which can be a folder on your Space. Spaces-API will only download the files inside this folder.

Copy a file inside your Space
-----------------------------

[](#copy-a-file-inside-your-space)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Copies the file to the same Space.
$my_space->copyFile("my-file.txt", "my-new-file.txt");

//Copies the file to another Space.
$my_space->copyFile("my-file.txt", "my-new-file.txt", "my-other-space");
```

- DigitalOcean only allows copying across Spaces in the same region.
- You can supply a fourth argument to set the new file's privacy (public/private).
- Returns info on the new file.

List all files inside your Space
--------------------------------

[](#list-all-files-inside-your-space)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Lists all files inside your Space.
$my_space->listFiles();

//Lists all files in a folder inside your Space.
$my_space->listFiles("my-folder");
```

- This function automatically iterates till it gets all files but you can set the second argument to false if you want to handle pagination yourself.
- If you set the second argument to false, you can set the third argument to a ContinuationToken.
- Returns an array of files but if the second argument is set to false, the original object is returned.

Check whether a file exists
---------------------------

[](#check-whether-a-file-exists)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns true if this file exists, otherwise false.
$my_space->fileExists("my-file.txt");
```

Get info on a file
------------------

[](#get-info-on-a-file)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns all available data on a file.
$my_space->fileInfo("my-file.txt");
```

Create a signed URL (Used for sharing private files)
----------------------------------------------------

[](#create-a-signed-url-used-for-sharing-private-files)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns a URL that'll work for 15 minutes for this file.
$my_space->signedURL("my-file.txt", "15 minutes");
```

Create an unsigned URL (Used for sharing public files)
------------------------------------------------------

[](#create-an-unsigned-url-used-for-sharing-public-files)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns a URL that'll work as long as the file is public.
$my_space->url("my-file.txt");
```

Change a file's privacy (Public &amp; Private ACL)
--------------------------------------------------

[](#change-a-files-privacy-public--private-acl)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Make a file public.
$my_space->filePrivacy("my-file.txt", "public");

//Make a file private.
$my_space->filePrivacy("my-file.txt", "private");
```

Delete a file
-------------

[](#delete-a-file)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Deletes a single file.
$my_space->deleteFile("my-file.txt");
```

Delete an entire folder
-----------------------

[](#delete-an-entire-folder)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Deletes all content of a folder (Or any file paths that match the provided check string).
$my_space->deleteFolder("my-folder");
```

Change your Space's privacy (ACL)
---------------------------------

[](#change-your-spaces-privacy-acl)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Makes your Space public. All your Space's files will be displayed to anyone.
$my_space->privacy("public");

//Makes your Space private.
$my_space->privacy("private");
```

List your Space's CORS rules
----------------------------

[](#list-your-spaces-cors-rules)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Returns an array of your Space's CORS rules.
$my_space->getCORS();
```

- This will throw an error if no CORS rules exist.

Set your Space's CORS rules
---------------------------

[](#set-your-spaces-cors-rules)

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//This allows all sources to use your file.
$my_space->setCORS([["origins" => ["*"], "methods" => ["GET", "HEAD", "OPTIONS"]]]);
```

Destroy your Space
------------------

[](#destroy-your-space)

Also deletes all files inside your Space

```
$my_space = Spaces("ACCESS KEY", "SECRET KEY")->space("my_space", "nyc3");

//Destroys your Space & deletes all its files.
$my_space->destroy();
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.1% 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 ~481 days

Total

2

Last Release

2049d ago

PHP version history (2 changes)v1PHP &gt;=5.3.0

v2PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ffe219fcd3d38abd6f400d8d7db0485761fb6c5f003548aa8bdbe9c6de2c253?d=identicon)[isaacongoma](/maintainers/isaacongoma)

---

Top Contributors

[![SociallyDev](https://avatars.githubusercontent.com/u/29544121?v=4)](https://github.com/SociallyDev "SociallyDev (59 commits)")[![isaacongoma](https://avatars.githubusercontent.com/u/21239787?v=4)](https://github.com/isaacongoma "isaacongoma (4 commits)")[![Abdelhady](https://avatars.githubusercontent.com/u/2075626?v=4)](https://github.com/Abdelhady "Abdelhady (2 commits)")[![AndreyNazarchuk](https://avatars.githubusercontent.com/u/7192775?v=4)](https://github.com/AndreyNazarchuk "AndreyNazarchuk (2 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")[![bilaltas](https://avatars.githubusercontent.com/u/12401765?v=4)](https://github.com/bilaltas "bilaltas (1 commits)")[![richellyitalo](https://avatars.githubusercontent.com/u/1899604?v=4)](https://github.com/richellyitalo "richellyitalo (1 commits)")[![alessandroaussems](https://avatars.githubusercontent.com/u/22371019?v=4)](https://github.com/alessandroaussems "alessandroaussems (1 commits)")

### Embed Badge

![Health badge](/badges/isaacongoma-spaces-api/health.svg)

```
[![Health](https://phpackages.com/badges/isaacongoma-spaces-api/health.svg)](https://phpackages.com/packages/isaacongoma-spaces-api)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k511.3M2.2k](/packages/aws-aws-sdk-php)[kreait/firebase-php

Firebase Admin SDK

2.4k39.7M72](/packages/kreait-firebase-php)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M786](/packages/league-flysystem-aws-s3-v3)[aws/aws-sdk-php-laravel

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

1.7k35.6M74](/packages/aws-aws-sdk-php-laravel)[stechstudio/laravel-zipstream

A fast and simple streaming zip file downloader for Laravel.

4633.7M3](/packages/stechstudio-laravel-zipstream)

PHPackages © 2026

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