2017 © Pedro Peláez
 

library oss-sdk-php

Aliyun OSS SDK for PHP

image

aliyuncs/oss-sdk-php

Aliyun OSS SDK for PHP

  • Monday, April 9, 2018
  • by hefei19861
  • Repository
  • 42 Watchers
  • 406 Stars
  • 240,338 Installations
  • PHP
  • 135 Dependents
  • 2 Suggesters
  • 160 Forks
  • 21 Open issues
  • 37 Versions
  • 22 % Grown

The README.md

Alibaba Cloud OSS SDK for PHP

Latest Stable Version Build Status Coverage Status, (*1)

README of Chinese

Overview

Alibaba Cloud Object Storage Service (OSS) is a cloud storage service provided by Alibaba Cloud, featuring a massive capacity, security, a low cost, and high reliability. You can upload and download data on any application anytime and anywhere by calling APIs, and perform simple management of data through the web console. The OSS can store any type of files and therefore applies to various websites, development enterprises and developers., (*2)

Run environment

  • PHP 5.3+.
  • cURL extension.

Tips:, (*3)

  • In Ubuntu, you can use the apt-get package manager to install the PHP cURL extension: sudo apt-get install php5-curl.

Install OSS PHP SDK

  • If you use the composer to manage project dependencies, run the following command in your project's root directory:, (*4)

    composer require aliyuncs/oss-sdk-php

    You can also declare the dependency on Alibaba Cloud OSS SDK for PHP in the composer.json file., (*5)

    "require": {
        "aliyuncs/oss-sdk-php": "~2.0"
    }

    Then run composer install to install the dependency. After the Composer Dependency Manager is installed, import the dependency in your PHP code:, (*6)

    require_once __DIR__ . '/vendor/autoload.php';
  • You can also directly download the packaged PHAR File, and introduce the file to your code:, (*7)

    require_once '/path/to/oss-sdk-php.phar';
  • Download the SDK source code, and introduce the autoload.php file under the SDK directory to your code:, (*8)

    require_once '/path/to/oss-sdk/autoload.php';

Quick use

Common classes

Class Explanation
OSS\OssClient OSS client class. An OssClient instance can be used to call the interface.
OSS\Core\OssException OSS Exception class . You only need to pay attention to this exception when you use the OssClient.

Initialize an OssClient

The SDK's operations for the OSS are performed through the OssClient class. The code below creates an OssClient object:, (*9)

<?php
$accessKeyId = "<AccessKeyID that you obtain from OSS>";
$accessKeySecret = "<AccessKeySecret that you obtain from OSS>";
$endpoint = "<Domain that you select to access an OSS data center, such as "oss-cn-hangzhou.aliyuncs.com>";
try {
    $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
} catch (OssException $e) {
    print $e->getMessage();
}

Operations on objects

Objects are the most basic data units on the OSS. You can simply consider objects as files. The following code uploads an object:, (*10)

<?php
$bucket= "<Name of the bucket in use. Pay attention to naming conventions>";
$object = "<Name of the object in use. Pay attention to naming conventions>";
$content = "Hello, OSS!"; // Content of the uploaded file
try {
    $ossClient->putObject($bucket, $object, $content);
} catch (OssException $e) {
    print $e->getMessage();
}

Operations on buckets

Buckets are the space that you use to manage the stored objects. It is an object management unit for users. Each object must belong to a bucket. You can create a bucket with the following code:, (*11)

<?php
$bucket= "<Name of the bucket in use. Pay attention to naming conventions>";
try {
    $ossClient->createBucket($bucket);
} catch (OssException $e) {
    print $e->getMessage();
}

Handle returned results

The OssClient provides the following two types of returned data from interfaces:, (*12)

  • Put and Delete interfaces: The PUT and DELETE operations are deemed successful if null is returned by the interfaces without OSSException.
  • Get and List interfaces: The GET and LIST operations are deemed successful if the desired data is returned by the interfaces without OSSException. For example,, (*13)

    <?php
    $bucketListInfo = $ossClient->listBuckets();
    $bucketList = $bucketListInfo->getBucketList();
    foreach($bucketList as $bucket) {
        print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreateDate() . "\n");
    }
    

    In the above code, $bucketListInfo falls into the 'OSS\Model\BucketListInfo' data type., (*14)

Run a sample project

  • Modify samples/Config.php to complete the configuration information.
  • Run cd samples/ && php RunAll.php.

Run a unit test

  • Run composer install to download the dependent libraries.
  • Set the environment variable., (*15)

    export OSS_ACCESS_KEY_ID=access-key-id
    export OSS_ACCESS_KEY_SECRET=access-key-secret
    export OSS_ENDPOINT=endpoint
    export OSS_BUCKET=bucket-name
  • Run php vendor/bin/phpunit, (*16)

License

  • MIT

Contact us

The Versions

09/04 2018

dev-concurrent

dev-concurrent http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

27/03 2018
03/02 2018

dev-master

9999999-dev http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

02/02 2018

dev-test-jenkins

dev-test-jenkins http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

24/01 2018

dev-global

dev-global http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

08/01 2018

v2.3.0

2.3.0.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

05/01 2018

dev-restore

dev-restore http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

28/12 2017

dev-symlink

dev-symlink http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

20/12 2017

dev-dev-head-bucket

dev-dev-head-bucket http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

18/12 2017

dev-support_proxy

dev-support_proxy http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

11/12 2017

dev-support_emptybody_

dev-support_emptybody_ http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

11/12 2017

dev-_emptybody

dev-_emptybody http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

07/12 2017

dev-support_emptybody

dev-support_emptybody http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

13/11 2017

dev-php7_1_2

dev-php7_1_2 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

22/06 2017

dev-supportrt_emptybody_

dev-supportrt_emptybody_ http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

21/06 2017

dev-refine-readme

dev-refine-readme http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

04/05 2017

dev-swoole_support

dev-swoole_support http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

25/04 2017

v2.2.4

2.2.4.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

14/04 2017

v2.2.3

2.2.3.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

07/03 2017

dev-crc64

dev-crc64 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

18/01 2017

v2.2.2

2.2.2.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

17/01 2017

dev-fix_php7_bug

dev-fix_php7_bug http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

01/12 2016

v2.2.1

2.2.1.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

29/11 2016

dev-fix_accept_encoding

dev-fix_accept_encoding http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

22/11 2016

v2.2.0

2.2.0.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

21/11 2016

dev-fix_return_null

dev-fix_return_null http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

15/11 2016

dev-live-channel

dev-live-channel http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

12/11 2016

v2.1.0

2.1.0.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

17/06 2016

v2.0.7

2.0.7.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

29/03 2016

v2.0.6

2.0.6.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

28/03 2016

dev-optimizer

dev-optimizer http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

26/01 2016

v2.0.5

2.0.5.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

26/12 2015

v2.0.4

2.0.4.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

25/12 2015

v2.0.3

2.0.3.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

19/12 2015

v2.0.2

2.0.2.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

14/12 2015

v2.0.1

2.0.1.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

28/11 2015

v2.0.0

2.0.0.0 http://www.aliyun.com/product/oss/

Aliyun OSS SDK for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires