PHP code example of mocode / flysystem-aliyunoss

1. Go to this page and download the library: Download mocode/flysystem-aliyunoss 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/ */

    

mocode / flysystem-aliyunoss example snippets


use League\Flysystem\Filesystem;
use Mocode\Flysystem\AliyunOss\AliyunOssAdapter;
use OSS\OssClient;

$accessId = 'Aliyun Oss Access Id';
$accessKey = 'Aliyun Oss Access Key';
$endPoint = 'Aliyun Oss endPoint';
$bucket = 'Aliyun Oss Bucket';
$domain = 'Aliyun Oss CDN Domain';

$client = new OssClient($accessId, $accessKey, $endPoint);
$adapter = new AliyunOssAdapter($client, $bucket, $domain);

$flysystem = new Filesystem($adapter);


bool $flysystem->write('file.md', 'contents');

bool $flysystem->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));

bool $flysystem->update('file.md', 'new contents');

bool $flysystem->updateStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));

bool $flysystem->rename('foo.md', 'bar.md');

bool $flysystem->copy('foo.md', 'foo2.md');

bool $flysystem->delete('file.md');

bool $flysystem->has('file.md');

string|false $flysystem->read('file.md');

array $flysystem->listContents();

array $flysystem->getMetadata('file.md');

int $flysystem->getSize('file.md');

string $flysystem->getAdapter()->getUrl('file.md'); 

string $flysystem->getMimetype('file.md');

int $flysystem->getTimestamp('file.md');


use Mocode\Flysystem\AliyunOss\\Plugins\PutFile;

$flysystem->addPlugin(new PutFile());

bool $flysystem->putFile('file.md', 'contents');

'oss' => [
    'driver'     => 'oss',
    'access_id'  => env('OSS_ACCESS_ID'), // Aliyun OSS AccessKeyId
    'access_key' => env('OSS_ACCESS_KEY'), // Aliyun OSS AccessKeySecret
    'bucket'     => env('OSS_BUCKET'), // OSS bucket name
    'endpoint'   => env('OSS_ENDPOINT'), // OSS 节点或自定义外部域名
    'domain'     => env('OSS_DOMAIN'), // CDN domain
],

'default' => 'oss'