PHP code example of hongfs / flysystem-cos
1. Go to this page and download the library: Download hongfs/flysystem-cos 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/ */
hongfs / flysystem-cos example snippets
use Hongfs\Cos\CosAdapter;
use League\Flysystem\Filesystem;
$config = [
'driver' => 'cos',
'secret_id' => '<secret_id>',
'secret_key' => '<secret_key>',
'bucket' => '<bucket-appid>',
'region' => '<region>',
];
$filesystem = new Filesystem(new CosAdapter($config));
bool $flysystem->has('1.txt');
bool $flysystem->write('1.txt', 'Test');
bool $flysystem->writeStream('1.txt', fopen('1.txt', 'r'));
bool $flysystem->update('1.txt', fopen('1.txt', 'r'));
bool $flysystem->updateStream('1.txt', fopen('1.txt', 'r'));
string $flysystem->read('1.txt');
resource $flysystem->readStream('1.txt');
bool $flysystem->rename('1.txt', '2.txt');
bool $flysystem->copy('1.txt', '2.txt');
bool $flysystem->createDir('Test/');
bool $flysystem->delete('1.txt');
bool $flysystem->deleteDir('Test/');
array $flysystem->getMetadata('1.txt');
int $flysystem->getSize('1.txt');
string $flysystem->getMimetype('1.txt');
int $flysystem->getTimestamp('1.txt');
array $flysystem->listContents();
// string $flysystem->setVisibility('1.txt', 'public');
// string $flysystem->getVisibility('1.txt');
'disks' => [
// ...
'cos' => [
'driver' => 'cos',
'secret_id' => '<secret_id>',
'secret_key' => '<secret_key>',
'bucket' => '<bucket-appid>',
'region' => '<region>',
'ssl' => true,
]
]
use Illuminate\Support\Facades\Storage;
$disk = Storage::disk('cos');
$disk->get('1.txt');
// https://laravel.com/docs/6.x/filesystem