PHP code example of tystuyfzand / seaweedfs-client
1. Go to this page and download the library: Download tystuyfzand/seaweedfs-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tystuyfzand / seaweedfs-client example snippets
$cache = new \SeaweedFS\Cache\FileCache('./cache');
$client = new SeaweedFS\SeaweedFS('127.0.0.1:9333', 'http', $cache);
// Upload a file and get the returned object (SeaweedFS\Models\File)
$file = $client->upload('test1234', 'test.txt');
// Update a file
$client->upload('Testing1234', 'test.txt', $file);
// Retrieve the file contents
$stream = $client->get($file->fid);
echo stream_get_contents($stream) . PHP_EOL;
// Delete a file
$client->delete($file->fid);
// Get a file's URL
echo "URL: " . $file->getFileUrl() . PHP_EOL;
// URLs can also be retrieved manually
$volume = $client->lookup($file->fid);
echo "URL (manual): " . $client->buildVolumeUrl($volume->getPublicUrl(), $file->fid) . PHP_EOL;