PHP code example of shaozeming / aliyun-oss

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

    

shaozeming / aliyun-oss example snippets




return [

       /**
        * oss 配置
        */
       'oss' => [
           'AccessKeyID' => 'LT********cgJFsp',
           'AccessKeySecret' => 'fNcK*************d6Gn',
           'endpoint' => 'oss-cn-beijing.aliyuncs.com',
           'bucket' => 'miji***a365',  //
           'is_cname' => false,  // 是否使用自己绑定域名
           'is_ssl' => false,  // 是否使用https
           'timeout' => 3600,  // 授权访问默认时间
       ]
];



use ShaoZeMing\AliOss\Services\OSSService;

 
    
           try {
                    $oss = new OSSService($config);
                    $result =  $oss->createBucket('shaozeming'); // 创建Bucket
                   
                   
                  //  $bucket= " <yourBucketName>";
                  //  $object = "<yourObjectName>";  
                  //  $content = "Hi, OSS.";
                  //  $result =  $oss->putObject($bucket,$object,$content); // 上传文件
                  //  .....
                    print_r($result);
                    return $result;
                } catch (OssException $e) {
                     $err = "Error : 错误:" . $e->getMessage();
                     echo $err . PHP_EOL;
                 } catch (\Exception $e) {
        //
                    $err = "Error : 错误:" . $e->getMessage();
                    echo $err . PHP_EOL;
        
                }