Cloud service

Using a storage bucket in PHP

Shipmate offers a Composer package that you can use within your PHP codebase to interact with your storage bucket. The package builds on Flysystem, a popular file storage library for PHP.

Installing the Composer package

To install the package, run the following command in your terminal:

composer require shipmate-io/shipmate

Storing and retrieving files

The following snippet illustrates how you can use the package in your codebase. However, you can use all of Flysystem's features to interact with your storage bucket.

use Shipmate\Shipmate\StorageBucket\StorageBucket;

$storageBucket = new StorageBucket(
    bucketName: getenv('SHIPMATE_STORAGE_BUCKET_NAME'),
);

// write a file
$storageBucket->write('avatars/1.jpg', $fileContents);

// read a file
$fileContents = $storageBucket->read('avatars/1.jpg');

// copy a file
$storageBucket->copy('avatars/1.jpg', 'avatars/2.jpg');