• Stars
    star
    975
  • Rank 45,308 (Top 1.0 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Aliyun OSS SDK for PHP

Alibaba Cloud OSS SDK for PHP

Latest Stable Version Build Status Coverage Status

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.

Run environment

  • PHP 5.3+.
  • cURL extension.

Tips:

  • 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:

      composer require aliyuncs/oss-sdk-php
    

    You can also declare the dependency on Alibaba Cloud OSS SDK for PHP in the composer.json file.

      "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:

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

      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:

      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:

<?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:

<?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:

<?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:

  • 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,

    <?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.

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.

      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

License

  • MIT

Contact us

More Repositories

1

oss-browser

OSS Browser 提供类似windows资源管理器功能。用户可以很方便的浏览文件,上传下载文件,支持断点续传等。
JavaScript
3,111
star
2

aliyun-openapi-java-sdk

Alibaba Cloud SDK for Java
Java
1,379
star
3

aliyun-oss-java-sdk

Aliyun OSS SDK for Java
Java
1,195
star
4

alibaba-cloud-sdk-go

Alibaba Cloud SDK for Go
Go
1,104
star
5

alicloud-android-demo

Java
982
star
6

aliyun-openapi-python-sdk

Alibaba Cloud SDK for Python
Python
980
star
7

aliyun-oss-go-sdk

Aliyun OSS SDK for Go
Go
933
star
8

aliyun-oss-python-sdk

Aliyun OSS SDK for Python
Python
907
star
9

darabonba

Darabonba 是一种用于 OpenAPI 的 DSL 语言,可以用来生成多语言的 SDK、Code Sample、Test Case 等代码
JavaScript
894
star
10

alibabacloud-alfa

阿里云微前端解决方案
TypeScript
838
star
11

aliyun-oss-android-sdk

Android SDK for aliyun object storage service
Java
793
star
12

aliyun-cli

Alibaba Cloud CLI
Go
770
star
13

ossfs

Export s3fs for aliyun oss.
C++
718
star
14

aliyun-openapi-php-sdk

[Abandoned] Open API SDK for PHP developers
PHP
605
star
15

terraform-provider-alicloud

Terraform AliCloud provider
Go
573
star
16

aliyun-openapi-net-sdk

Alibaba Cloud SDK for .NET
C#
534
star
17

rds_dbsync

围绕 PostgreSQL Greenplum ,实现易用的数据的互迁功能项目
C
528
star
18

openapi-sdk-php

Alibaba Cloud SDK for PHP
PHP
501
star
19

iotkit-embedded

高速镜像: https://code.aliyun.com/linkkit/c-sdk
C
492
star
20

aliyun-oss-ios-sdk

iOS SDK for aliyun object storage service
Objective-C
450
star
21

alicloud-ios-demo

Demos for AMS iOS SDKs
Objective-C
427
star
22

ossutil

A user friendly command line tool to access AliCloud OSS.
Go
427
star
23

aliyun-odps-python-sdk

ODPS Python SDK and data analysis framework
Python
407
star
24

api-gateway-demo-sign-java

aliyun api gateway request signature demo by java
Java
371
star
25

alibabacloud-microservice-demo

An Alibaba Cloud native microservice demo powered by Apache Dubbo and Spring Cloud Alibaba
Java
364
star
26

aliyun-oss-csharp-sdk

Aliyun OSS SDK for C#
C#
360
star
27

NeWCRFs

Python
344
star
28

surftrace

surftrace is a tool that allows you to surf the linux kernel
Python
332
star
29

conditional-lane-detection

Python
328
star
30

aliyun-log-jaeger

Go
294
star
31

tablestore-examples

Example code for aliyun tablestore.
Java
236
star
32

tablestore-timeline

TableStore-Timeline Model for Social scene
Java
236
star
33

coolbpf

C
222
star
34

openapi-sdk-php-client

Official repository of the Alibaba Cloud Client for PHP
PHP
214
star
35

aliyun-log-c-sdk

Aliyun LOG Producer for C/C++
C
212
star
36

aliyun-log-logback-appender

Java
176
star
37

openapi-core-nodejs-sdk

OpenAPI POP core SDK for Node.js
JavaScript
175
star
38

aliyun-log-android-sdk

Java
174
star
39

alibabacloud-jindodata

alibabacloud-jindodata
170
star
40

aliyun-emapreduce-datasources

Extended datasource support for Spark/Hadoop on Aliyun E-MapReduce.
Scala
168
star
41

aliyun-log-python-sdk

Use python to manage, produce and consume data with Aliyun Log Service.
Python
161
star
42

aliyun-oss-react-native

Objective-C
148
star
43

aliyun-apsaradb-hbase-demo

C++
147
star
44

data-mapping-component

A React Component which focus on Data-Mapping & Table-Field-Mapping.(基于React的数据/表字段映射组件)
JavaScript
146
star
45

aliyun-oss-c-sdk

Aliyun OSS SDK for C
C
144
star
46

django-oss-storage

Django storage backends for AliCloud OSS.
Python
142
star
47

aliyun-oss-ruby-sdk

Aliyun OSS SDK for Ruby
Ruby
138
star
48

ram-policy-editor

AliCloud RAM Policy Editor for OSS
JavaScript
135
star
49

serverless-aliyun-function-compute

Serverless Alibaba Cloud Function Compute Plugin – Add Alibaba Cloud Function Compute support to the Serverless Framework
JavaScript
133
star
50

react-visual-modeling

A DAG React Component for visualization modeling, suitable for UML, database modeling, data warehouse construction.(一个基于React的数据可视化建模的DAG图,适用于UML,数据库建模,数据仓库建设等业务)
JavaScript
132
star
51

alibabacloud-console-components

阿里云企业云管理平台 UI 组件库
TypeScript
131
star
52

fc-nodejs-sdk

The Node.js SDK of FunctionCompute.
JavaScript
130
star
53

aliyun-log-java-sdk

Java
130
star
54

aliyun-cms-grafana

JavaScript
127
star
55

aliyun-log-java-producer

Aliyun LOG Java Producer
Java
124
star
56

aliyun-emapreduce-demo

Java
123
star
57

alibabacloud-quantization-networks

alibabacloud-quantization-networks
Python
122
star
58

aliyun-odps-jdbc

JDBC Driver for ODPS
Java
118
star
59

alicloud-ams-demo

C#
117
star
60

aliyun-maxcompute-data-collectors

Java
113
star
61

alibabacloud-iot-device-sdk

alibaba cloud for iot device javascript SDK , connect with linkplatform , run at node/broswer/winxin min program /ali min program. 阿里云IoT物联网平台javascript版本sdk,可以运行在node/broswer/winxin min program /ali min program. 阿里云IoT物联网平台javascript版本sdk,可以运行在node/broswer/winxin min program /ali min program
JavaScript
110
star
62

api-gateway-nodejs-sdk

The API Gateway SDK for Node.js
JavaScript
104
star
63

MaxCompute-Spark

MaxCompute spark demo for building a runnable application.
Scala
104
star
64

gm-jsse

开源国密通信纯 Java JSSE 实现
Java
95
star
65

cloud-design

阿里云前端组件库,由专有云&公有云前端团队共建
CSS
95
star
66

aliyun-openapi-cpp-sdk

Alibaba Cloud SDK for C++
C++
90
star
67

aliyun-odps-console

ODPS Console Source Code.
Java
90
star
68

aliyun-tablestore-nodejs-sdk

Aliyun TableStore(原OTS) SDK for Node.js
JavaScript
88
star
69

aliyun-odps-java-sdk

ODPS SDK for Java Developers
Java
85
star
70

iotx-api-demo

PHP
83
star
71

aliyun-log-ios-sdk

Aliyun LOG iOS SDK
Swift
81
star
72

algorithm-base

让算法工程化更简单
Python
81
star
73

aliyun-openapi-nodejs-sdk

Alibaba Cloud SDK for Node.js
JavaScript
80
star
74

plugsched

Live upgrade Linux kernel scheduler subsystem
Python
77
star
75

DCT-Mask

Python
76
star
76

alibabacloud-redis-training-demo

Java
76
star
77

aliyun-oss-php-sdk-laravel

A Laravel service provider for the AliCloud OSS SDK for PHP
PHP
75
star
78

aliyun-tablestore-go-sdk

TableStore SDK for Golang
Go
75
star
79

fc-docker

Dockerfiles for local building or running function of FC
Dockerfile
74
star
80

aliyun-specs

Aliyun Mobile Service CocoaPods specs.
Ruby
74
star
81

dro-sfm

Python
74
star
82

elasticsearch-repository-oss

Java
73
star
83

packagist-mirror

Alibaba Cloud Packagist Mirror
Go
73
star
84

alibabacloud-console-design

阿里云管平台研发解决方案
TypeScript
73
star
85

alibabacloud-sdk

Tea
72
star
86

react-monitor-dag

A React-based operation/monitoring DAG diagram.(基于React的运维/监控DAG图)
JavaScript
68
star
87

aliyun-log-php-sdk

PHP
66
star
88

aliyun-tsdb-java-sdk

Aliyun TSDB SDK for Java
Java
64
star
89

aliyun-log-log4j-appender

aliyun-log-log4j-appender
Java
63
star
90

aliyun_assist_client

Aliyun Assist Client 阿里云 云助手
Go
62
star
91

fc-java-sdk

The Java SDK of FunctionCompute.
Java
61
star
92

alibabacloud-hologres-connectors

alibabacloud-hologres-connectors
Java
61
star
93

oss-ftp

The ftp proxy for Aliyun OSS.
Python
61
star
94

aliyun-log-cli

Command Line Interface for Aliyun Log Service
Python
59
star
95

csb-sdk

The CSB-SDK is a client-side invocation SDK for HTTP or Web Service API opened by the CSB (Cloud Service Bus) product. It is responsible for invoking the open API and signing the request information.
Java
58
star
96

aliyun-log-flink-connector

flink log connector
Java
58
star
97

ossimport

Data migration tool
57
star
98

oss-emulator

OSS Emulator
Ruby
57
star
99

fc-python-sdk

The python sdk of Aliyun FunctionCompute
Python
55
star
100

aliyun-log-dotnetcore-sdk

C#
54
star