1. Go to this page and download the library: Download jichangfeng/yun-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/ */
jichangfeng / yun-storage example snippets
try {
//Make a storage manager instance.
$storage = new \YunStorage\StorageManager();
//
//Register Aliyun OSS Storage Adapter
//Note: The first registered storage adapter will be the default.
$storage->registerAdapter('oss', [
'accessKeyId' => '',
'accessKeySecret' => '',
'endpoint' => ''
]);
//
//Register Tencent COS Storage Adapter
$storage->registerAdapter('cos', [
'accessKeyId' => '',
'accessKeySecret' => '',
'region' => '',
'schema' => '',
'appid' => ''
]);
//
//Set the default storage adapter name. Supported: "oss", "cos"
$storage->setDefaultAdapter('oss');
//
//If your application interacts with default storage adapter.
$storage->putObject($bucket, $object, $content);
//
//If your application interacts with multiple storage adapters,
//you may use the 'adapter' method to work on a particular storage adapter.
$storage->adapter('oss')->putObject($bucket, $object, $content);
$storage->adapter('cos')->putObject($bucket, $object, $content);
//
//Directly call the storage object at the back-end of the storage adapter
$storage->adapter()->client();
$storage->adapter('oss')->client()->listObjects($bucket, $options);
$storage->adapter('cos')->client()->listObjects($arg);
} catch (\Exception $e) {
echo $e->getMessage();
}
try {
//Creates bucket
$storage->createBucket($bucket);
//
//Checks if a bucket exists
$storage->doesBucketExist($bucket);
//
//Deletes bucket
$storage->deleteBucket($bucket);
//
//Lists the Bucket
$storage->listBuckets();
//
//Uploads the $content object.
$storage->putObject($bucket, $object, $content);
//
//Checks if the object exists
$storage->doesObjectExist($bucket, $object);
//
//Deletes a object
$storage->deleteObject($bucket, $object);
//
//Deletes multiple objects in a bucket
$storage->deleteObjects($bucket, $objects);
//
//Gets Object content
$storage->getObject($bucket, $object);
//
//Lists the bucket's object keys
$storage->listObjectKeys($bucket, $prefix);
//
//Uploads a local file
$storage->uploadFile($bucket, $object, $localfile);
//
//Downloads to local file
$storage->downloadFile($bucket, $object, $localfile);
//
// Gets the storage client, return the actual storage object
$storage->adapter()->client();
} catch (\Exception $e) {
echo $e->getMessage();
}