1. Go to this page and download the library: Download codeinc/object-storage 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/ */
codeinc / object-storage example snippets
use CodeInc\ObjectStorage;
// SFTP container with private key authentication
$sftpDirectory = ObjectStorage\Sftp\SftpDirectory::factoryPubKey(
"/remote/path/to/files",
"hostname.local",
"remote-user",
"path/to/public-key.pub",
"path/to/private-key",
"optional-key-passphrase"
22 // optional port number
);
// SFTP container with user/password authentication
$sftpDirectory = ObjectStorage\Sftp\SftpDirectory::factoryPassword(
"hostname.local",
"remote-user",
"remote-password",
22 // optional port number
);
// Local file system container
$localDirectory = ObjectStorage\Local\LocalDirectory::factory(
"/path/to/files"
);
// Swift container
$swiftContainer = ObjectStorage\Swift\SwiftContainer::factory(
"container-name",
"container-swift-region",
"https://open-stack-auth-url.com",
"open-stack-user",
"open-stack-password",
"open-stack-tenant-id",
"open-stack-tenant-name"
);
// B2 container
$b2Bucket = ObjectStorage\BackBlazeB2\B2Bucket::factory(
"container-or-bucket-name",
"b2-account-id",
"b2-application-key"
);
use CodeInc\ObjectStorage;
// from an existing file
$object = new ObjectStorage\Utils\InlineObject("test.jpg");
$object->setFileContent("/path/to/test.jpg");
// from a string
$object = new ObjectStorage\Utils\InlineObject("test.txt");
$object->setStringContent("C'est un test au format texte !");
// uploading an object
$container->uploadObject($object, 'optional-new-object-name.txt');
// transfering an object from a container to another
$destinationContainer->uploadObject(
$sourceContainer->getObject('test.jpg')
);
foreach ($container as $file) {
var_dump($file->getName());
}
// from a container
$container->deleteObject("test.jpg");
// from an object
$object = $container->getObject('test.jpg');
if ($object instanceof StoreObjectDeleteInterface) {
$object->delete();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.