PHP code example of xy_jx / flysystem-cos

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

    

xy_jx / flysystem-cos example snippets


use League\Flysystem\Filesystem;
use xy_jx\Flysystem\CosAdapter;

$config = [
    'region'      => 'ap-guangzhou',
    'credentials' => [
        'appId'      => 1234567889, // 域名中数字部分
        'secretId'   => 'AKIDS5jNr5NNygGxxxxxxxxxxxxxxxxxx',
        'secretKey'  => 'NfszEWmyDqGmao0a4XS8wxxxxxxxxxxxx',
    ],
    'bucket'          => 'test',
    'timeout'         => 60,
    'connect_timeout' => 60,
    'cdn'             => '您的 CDN 域名',
    'scheme'          => 'https',
    'read_from_cdn'   => false,
];

$adapter = new CosAdapter($config);

$flysystem = new League\Flysystem\Filesystem($adapter);



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

bool $flysystem->write('file.md', 'http://httpbin.org/robots.txt', ['mime' => 'application/redirect302']);

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');