Package · sdk-s5w

Quick start

One scenario from start to finish: a script connects to S5W, sets up a folder for reports, uploads two files into it, finds them in a list, renames one and cleans up after itself. Every step shows what the server returned.

Needs an S5W address and a FULL keyTime ~5 minutes

Before you start

Install the package and put the address and the key into environment variables — how, and where to get a key, is on the Installation page.

bash
composer require flytachi/winter-sdk-s5w
export S5W_URL=https://s5.example.com
export S5W_KEY=s5w_9f3c…

All the code below is one file, quickstart.php, that grows with every step. The full version is at the end of the page.

Step 1. Connect and check the key

quickstart.php
<?php

require __DIR__ . '/vendor/autoload.php';

use Flytachi\Winter\SDK\S5w\S5w;

$s5w = S5w::connect(getenv('S5W_URL'), getenv('S5W_KEY'));

$key = $s5w->check();
printf(
  "Bucket %s, access %s, %.1f MB free\n",
  $key->bucket->name,
  $key->access->name,
  $key->storage->free / 1024 / 1024,
);
bash
$ php quickstart.php
Bucket media, access FULL, 445.9 MB free

check() is the one call that works with any key. It answers “does the key work and what is behind it”. If the key does not fit, you get an exception instead of a result — they are listed on the Installation page.

Step 2. Set up a folder

Folders are optional in S5W, but handy: a folder has a visibility, a retention period and a cache policy, and they apply to every file inside. Let’s set up a folder for reports:

quickstart.php
$folder = $s5w->folders()->ensure('reports');

echo "Folder {$folder->name}, public: " . ($folder->public ? 'yes' : 'no') . "\n";
bash
Folder reports, public: no

ensure() creates the folder if it is missing and returns the existing one as it is otherwise. So the script can be run any number of times.

Step 3. Upload files

Let’s upload two files: one generated right in memory, the other from disk.

quickstart.php
$files = $s5w->files();

// from memory: e.g. a report the application has just built
$csv = $files->uploadContent("date,total\n2026-11-01,42\n", 'november.csv', folder: $folder);

// from disk
file_put_contents('/tmp/notes.txt', 'Quarterly notes');
$notes = $files->upload('/tmp/notes.txt', folder: $folder);

foreach ([$csv, $notes] as $file) {
  printf("%s  %-14s %4d bytes  %s\n", $file->id, $file->name, $file->content->size, $file->content->mime);
}
bash
8bRb7sM8LJR4d4bE  november.csv     25 bytes  text/csv
xm6EBYd2qxCEBnbh  notes.txt        15 bytes  text/plain

Remember the key field — id. It is the file’s 16-character identifier: every other method and every delivery address uses it. You can store it in your database and show it in URLs.

The server decides the type

The SDK does not send a MIME type — the server detects it from the content. The name matters only for text formats (.csv, .md, .yaml) that look like plain text byte by byte.

Step 4. Find the files in a list

quickstart.php
$page = $files->list(folder: $folder);

echo "{$page->total} file(s) in the folder:\n";
foreach ($page as $file) {
  echo "  {$file->name}\n";
}
bash
2 file(s) in the folder:
notes.txt
november.csv

list() returns one page — a Page object. You can foreach over it, and total says how many files match the filter across all pages. To walk every page in turn there is all() — see Folders and files.

Step 5. Rename

quickstart.php
$notes = $files->rename($notes, 'Q4-notes.txt');

echo "Now {$notes->name}, same id: {$notes->id}\n";
bash
Now Q4-notes.txt, same id: xm6EBYd2qxCEBnbh

Renaming does not change the id, so every address already handed out keeps working.

Step 6. Clean up

quickstart.php
$files->delete($csv);
$files->delete($notes);
$s5w->folders()->delete('reports');

echo "Done, the bucket is clean\n";
bash
Done, the bucket is clean

Deleting a folder deletes its files

folders()->delete() deletes the folder together with every file in it, with no confirmation. Here the files are deleted first only for clarity — deleting the folder alone would have been enough.

The whole script

quickstart.php
<?php

require __DIR__ . '/vendor/autoload.php';

use Flytachi\Winter\SDK\S5w\S5w;

$s5w = S5w::connect(getenv('S5W_URL'), getenv('S5W_KEY'));

// 1. the key
$key = $s5w->check();
printf(
  "Bucket %s, access %s, %.1f MB free\n",
  $key->bucket->name,
  $key->access->name,
  $key->storage->free / 1024 / 1024,
);

// 2. a folder
$folder = $s5w->folders()->ensure('reports');
echo "Folder {$folder->name}, public: " . ($folder->public ? 'yes' : 'no') . "\n";

// 3. uploads
$files = $s5w->files();
$csv = $files->uploadContent("date,total\n2026-11-01,42\n", 'november.csv', folder: $folder);
file_put_contents('/tmp/notes.txt', 'Quarterly notes');
$notes = $files->upload('/tmp/notes.txt', folder: $folder);
foreach ([$csv, $notes] as $file) {
  printf("%s  %-14s %4d bytes  %s\n", $file->id, $file->name, $file->content->size, $file->content->mime);
}

// 4. the list
$page = $files->list(folder: $folder);
echo "{$page->total} file(s) in the folder:\n";
foreach ($page as $file) {
  echo "  {$file->name}\n";
}

// 5. rename
$notes = $files->rename($notes, 'Q4-notes.txt');
echo "Now {$notes->name}, same id: {$notes->id}\n";

// 6. clean up
$files->delete($csv);
$files->delete($notes);
$s5w->folders()->delete('reports');
echo "Done, the bucket is clean\n";

Next