1. Go to this page and download the library: Download fei/filer-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/ */
fei / filer-client example snippets
use Fei\Service\Filer\Client\Filer;
use Fei\ApiClient\Transport\BasicTransport;
use Fei\ApiClient\Transport\BeanstalkProxyTransport;
use Pheanstalk\Pheanstalk;
$filer = new Filer([
Filer::OPTION_BASEURL => 'https://filer.api.com', // Put your filer API base URL here
Filer::OPTION_HEADER_AUTHORIZATION => 'apiKey'
]);
$filer->setTransport(new BasicTransport());
$proxy = new BeanstalkProxyTransport();
$proxy->setPheanstalk(new Pheanstalk('127.0.0.1'));
$filer->setAsyncTransport($proxy);
// Use the filer client...
use Fei\Service\Filer\Client\Filer;
use Fei\Service\Filer\Client\Builder\SearchBuilder;
// Creating a Filer client instance...
$filer = new Filer([
Filer::OPTION_BASEURL => 'http://127.0.0.1:8080',
Filer::OPTION_HEADER_AUTHORIZATION => 'apiKey'
]);
$builder = new SearchBuilder();
$builder->category()->equal(1);
$builder->context()->key('test 1')->equal('test 1');
$builder->context()->key('test 2')->equal('test 2');
$builder->filename()->beginsWith('avatar');
$files = $filer->search($builder);
use Fei\Service\Filer\Entity\File;
use Fei\Service\Filer\Client\Filer;
// Creating a Filer client instance...
$file = new File();
$file->setCategory(File::CATEGORY_IMG)
->setContexts(['test 1' => 'test 1', 'test 2' => 'test 2'])
->setFile(new SplFileObject(__DIR__ . '/../file/path.pdf');
$uuid = $filer->upload($file, Filer::ASYNC_UPLOAD);
// Add a new revision:
$uuid = $filer->upload(
(new File())
->setCategory(File::CATEGORY_IMG)
->setUuid($uuid)
->setFile(new SplFileObject(__DIR__ . '/../file/path2.pdf')),
Filer::NEW_REVISION
);
use Fei\Service\Filer\Client\Filer;
// Creating a Filer client instance...
$file = Filer::embed('/path/to/the/file.pdf');
$file = $filer->upload($file, Filer::ASYNC_UPLOAD);
// Creating a Filer client instance...
$file = $filer->retrieve('bck1:f6461366-a414-4b98-a76d-d7b190252e74');
use Fei\Service\Filer\Entity\File;
// Creating a Filer client instance...
$filer->delete('bck1:f6461366-a414-4b98-a76d-d7b190252e74');
echo $filer->retrieve('bck1:f6461366-a414-4b98-a76d-d7b190252e74') instanceof File; // false
use Fei\Service\Filer\Entity\File;
use Fei\Service\Filer\Client\Filer;
// Creating a Filer client instance...
$uuid = $filer->upload(
(new File())
->setCategory(File::CATEGORY_IMG)
->setContexts(['test 1' => 'test 1', 'test 2' => 'test 2'])
->setFile(new SplFileObject(__DIR__ . '/../tests/_data/avatar.png')),
Filer::ASYNC_UPLOAD
);
$uuid = $filer->upload(
(new File())
->setCategory(File::CATEGORY_IMG)
->setUuid($uuid)
->setFile(new SplFileObject(__DIR__ . '/../tests/_data/capture.png')),
Filer::ASYNC_UPLOAD|Filer::NEW_REVISION
);
// truncate the file and keep the last revisions
$filer->truncate($uuid, 1);
use Fei\Service\Filer\Entity\File;
// Creating a Filer client instance...
$uuid = $filer->upload(
(new File())
->setCategory(File::CATEGORY_IMG)
->setContexts(['test 1' => 'test 1', 'test 2' => 'test 2'])
->setFile(new SplFileObject(__DIR__ . '/../tests/_data/file.png'))
);
// save the file at this location on the local server
$filer->save($uuid, __DIR__ . '/../tests/_data/save/file_saved.png');
use Fei\Service\Filer\Entity\File;
// Creating a Filer client instance...
$uuid = $filer->upload(
(new File())
->setCategory(File::CATEGORY_IMG)
->setContexts(['test 1' => 'test 1', 'test 2' => 'test 2'])
->setFile(new SplFileObject(__DIR__ . '/../tests/_data/avatar.png'))
);
// Serve the file
$filer->serve($uuid);