PHP code example of jichangfeng / laravel-yun-storage
1. Go to this page and download the library: Download jichangfeng/laravel-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 / laravel-yun-storage example snippets
return [
/*
|--------------------------------------------------------------------------
| Default Storage Adapter
|--------------------------------------------------------------------------
|
| This option controls the default storage adapter that gets used while
| using this yun storage library.
|
| Supported: "oss", "cos"
|
*/
'default' => env('YUN_STORAGE_ADAPTER', ''),
/*
|--------------------------------------------------------------------------
| Storage Adapters
|--------------------------------------------------------------------------
|
| Here you may define all of the storage "adapters" for your application as
| well as their storage adapters.
|
*/
'adapters' => [
'oss' => [
'accessKeyId' => env('YUN_STORAGE_OSS_ACCESS_KEY_ID', ''),
'accessKeySecret' => env('YUN_STORAGE_OSS_ACCESS_KEY_SECRET', ''),
'endpoint' => env('YUN_STORAGE_OSS_ENDPOINT', ''),
],
'cos' => [
'accessKeyId' => env('YUN_STORAGE_COS_ACCESS_KEY_ID', ''),
'accessKeySecret' => env('YUN_STORAGE_COS_ACCESS_KEY_SECRET', ''),
'region' => env('YUN_STORAGE_COS_REGION', ''),
'schema' => env('YUN_STORAGE_COS_SCHEMA', 'http'),
'appid' => env('YUN_STORAGE_COS_APPID', ''),
]
]
];
try {
//Set the default storage adapter name. Supported: "oss", "cos"
\YunStorage\Laravel\YunStorageFacade::setDefaultAdapter('oss');
//
//If your application interacts with default storage adapter.
\YunStorage\Laravel\YunStorageFacade::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.
\YunStorage\Laravel\YunStorageFacade::adapter('oss')->putObject($bucket, $object, $content);
\YunStorage\Laravel\YunStorageFacade::adapter('cos')->putObject($bucket, $object, $content);
//
//Directly call the storage object at the back-end of the storage adapter
\YunStorage\Laravel\YunStorageFacade::adapter()->client();
\YunStorage\Laravel\YunStorageFacade::adapter('oss')->client()->listObjects($bucket, $options);
\YunStorage\Laravel\YunStorageFacade::adapter('cos')->client()->listObjects($arg);
} catch (\Exception $e) {
echo $e->getMessage();
}
try {
//Creates bucket
\YunStorage\Laravel\YunStorageFacade::createBucket($bucket);
//
//Checks if a bucket exists
\YunStorage\Laravel\YunStorageFacade::doesBucketExist($bucket);
//
//Deletes bucket
\YunStorage\Laravel\YunStorageFacade::deleteBucket($bucket);
//
//Lists the Bucket
\YunStorage\Laravel\YunStorageFacade::listBuckets();
//
//Uploads the $content object.
\YunStorage\Laravel\YunStorageFacade::putObject($bucket, $object, $content);
//
//Checks if the object exists
\YunStorage\Laravel\YunStorageFacade::doesObjectExist($bucket, $object);
//
//Deletes a object
\YunStorage\Laravel\YunStorageFacade::deleteObject($bucket, $object);
//
//Deletes multiple objects in a bucket
\YunStorage\Laravel\YunStorageFacade::deleteObjects($bucket, $objects);
//
//Gets Object content
\YunStorage\Laravel\YunStorageFacade::getObject($bucket, $object);
//
//Lists the bucket's object keys
\YunStorage\Laravel\YunStorageFacade::listObjectKeys($bucket, $prefix);
//
//Uploads a local file
\YunStorage\Laravel\YunStorageFacade::uploadFile($bucket, $object, $localfile);
//
//Downloads to local file
\YunStorage\Laravel\YunStorageFacade::downloadFile($bucket, $object, $localfile);
//
// Gets the storage client, return the actual storage object
\YunStorage\Laravel\YunStorageFacade::adapter()->client();
} catch (\Exception $e) {
echo $e->getMessage();
}