PHP code example of zencodex / flysystem-upyun
1. Go to this page and download the library: Download zencodex/flysystem-upyun 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/ */
zencodex / flysystem-upyun example snippets
use League\Flysystem\Filesystem;
use ZenCodex\Support\Flysystem\Adapter\UpyunAdapter
$config => [
'driver' => 'upyun',
'bucket' => '', // 服务名字
'operator' => '', // 操作员的名字
'password' => '', // 操作员的密码
'domain' => '', // 服务分配的域名
'protocol' => 'https', // 服务使用的协议,如需使用 http,在此配置 http
];
$adapter = new UpyunAdapter((object)$config);
// 或在 Laravel 中获取 $adapter
$adapter = Storage::disk('upyun')->getAdapter();
$adapter->write('file.md', 'contents');
$adapter->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
$adapter->rename('foo.md', 'bar.md');
$adapter->copy('foo.md', 'foo2.md');
$adapter->delete('file.md');
$adapter->getUrl('/path/foo/bar/file.md');
$adapter->fileExists('file.md');
$adapter->directoryExists('path/to/dir');
$adapter->read('file.md');
// ...
// $adapter 详细调用方法可参考: src/Adapter/UpyunAdapter.php
// $clientHandler 为 Upyun::class, 直接调用 Upyun 内的方法
$clientHandler = $adapter->getClientHandler();
$clientHandler->purge($remoteUrl);
$clientHandler->usage();
'providers' => [
// ...
ZenCodex\Support\Flysystem\UpyunServiceProvider::class,
],
'disks' => [
// ...
'upyun' => [
'driver' => 'upyun',
'bucket' => env('UPYUN_BUCKET', ''),// 服务名字
'operator' => env('UPYUN_OPERATOR_NAME', ''), // 操作员的名字
'password' => env('UPYUN_OPERATOR_PASSWORD', ''), // 操作员的密码
'domain' => env('UPYUN_DOMAIN', ''), // 服务分配的域名
'protocol' => 'https', // 服务使用的协议,如需使用 http,在此配置 http
]
]
$disk = Storage::disk('upyun');
$disk->write('file.md', 'contents');
$disk->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
$disk->rename('foo.md', 'bar.md');
$disk->copy('foo.md', 'foo2.md');
$disk->delete('file.md');
$disk->fileExists('file.md');
$disk->directoryExists('path/to/dir');
$disk->read('file.md');
$disk->listContents();
$disk->fileSize('file.md');
$disk->mimeType('file.md');
$disk->url('/path/foo/bar/file.md');