PHP code example of onekb / hyperf-oss

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

    

onekb / hyperf-oss example snippets


// 方法一:hyperf类里面自动注入
/**
 * @Inject
 * @var HyperfOSS\OSS
 */
protected $oss;

// 方法二:主动new
$oss = new OSS();

// 方法三:在容器里拿出来
$oss = Hyperf\Utils\ApplicationContext::getContainer()->get(OSS::class)

// 直接调用方法
$oss->signUrl('bucket-name', 'filename.pdf', 3600, OssClient::OSS_HTTP_PUT);
// 使用其他配置
$oss->make('other-config')->signUrl('bucket-name', 'filename.pdf', 3600, OssClient::OSS_HTTP_PUT);
shell
php bin/hyperf.php vendor:publish onekb/hyperf-oss