1. Go to this page and download the library: Download sunkan/php-mogilefs 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/ */
sunkan / php-mogilefs example snippets
$connection = new MogileFs\Connection([
'127.0.0.1:7001'
]);
//or
$connection = new MogileFs\Connection([
[
'host' => '127.0.0.1',
'port' => 7001
]
]);
$domainClient = new MogileFs\Client\DomainClient($connection);
try {
$domain = $domainClient->create('example.com');
$domain->getDomain(); // domain name
$domain->getClasses(); // array of classes
} catch(MogileFs\Exception $e) {
$e->getMessage() === 'domain_exists';
}
$fileClient = new MogileFs\Client\FileClient($connection, 'example.com');
$response = $fileClient->delete('test/key');
$response->isSuccess();
$fileClient = new MogileFs\Client\FileClient($connection, 'example.com');
$response = $fileClient->rename('test/key', 'test/key2');
$response->isSuccess();
$fileClient = new MogileFs\Client\FileClient($connection, 'example.com');
$collection = $fileClient->listKeys($prefix, $suffix, $limit);
$collection; // contains file keys nothing else
$collection = $fileClient->listFids($fromFid, $toFid);
$collection; // contains File objects with information about all files in range
$class = "blob-class";
$file = new MogileFs\File\BlobFile('raw data', $class)
$class = "local-file-class";
$file = new MogileFs\File\LocalFile('/path/to/file', $class)
$class = "psr7-file-class";
$uploadFile = $request->getUploadedFiles()['file'];
$file = new MogileFs\File\Psr7File($uploadFile, $class)
//or
$stream;// instance of Psr\Http\Message\StreamInterface
$file = new MogileFs\File\Psr7File($stream, $class)
$class = "resource-file-class";
$resource = fopen('file', 'r'); // should work with any stream context
$file = new MogileFs\File\ResourceFile($resource, $class)
$factory = new MogileFs\File\Factory();
$file = $factory($fileContent, $class);
$fileClient = new MogileFs\Client\FileClient($connection, 'example.com');
$factory = new MogileFs\File\Factory();
$key = 'test/key';
$file = $factory($fileContent, $class);
$response = $fileClient->upload($key, $file);
if ($response->isSuccess()) {
$path = $fileClient->get($key);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.