# Alibaba Cloud OSS SDK for PHP
[![Latest Stable Version](https://poser.pugx.org/aliyuncs/oss-sdk-php/v/stable)](https://packagist.org/packages/aliyuncs/oss-sdk-php)
[![Build Status](https://travis-ci.org/aliyun/aliyun-oss-php-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-php-sdk)
[![Coverage Status](https://coveralls.io/repos/github/aliyun/aliyun-oss-php-sdk/badge.svg?branch=master)](https://coveralls.io/github/aliyun/aliyun-oss-php-sdk?branch=master)
## [README of Chinese](https://github.com/aliyun/aliyun-oss-php-sdk/blob/master/README-CN.md)
## 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][releases-page], 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
<?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
<?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
<?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
<?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
- [Alibaba Cloud OSS official website](http://oss.aliyun.com).
- [Alibaba Cloud OSS official forum](http://bbs.aliyun.com).
- [Alibaba Cloud OSS official documentation center](http://www.aliyun.com/product/oss#Docs).
- Alibaba Cloud official technical support: [Submit a ticket](https://workorder.console.aliyun.com/#/ticket/createIndex).
[releases-page]: https://github.com/aliyun/aliyun-oss-php-sdk/releases
[phar-composer]: https://github.com/clue/phar-composer
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
阿里云OSS上传视频上传图片sdk及样例代码 (306个子文件)
.gitignore 68B
example.jpg 21KB
composer.json 556B
LICENSE 2KB
README.md 6KB
README-CN.md 5KB
CHANGELOG.md 2KB
LICENSE.md 1KB
OssClient.php 100KB
AliyunVodUploader.php 31KB
RequestCore.php 29KB
OssClientObjectTest.php 20KB
Object.php 15KB
OssUtil.php 13KB
OssClientMultipartUploadTest.php 11KB
CallbackTest.php 11KB
BucketLiveChannelTest.php 11KB
MimeTypes.php 10KB
DefaultAcsClient.php 10KB
LiveChannelXmlTest.php 9KB
RoaAcsRequest.php 9KB
AliyunVodUtils.php 8KB
DefaultProfile.php 8KB
OssClientTest.php 7KB
OssUtilTest.php 7KB
AcsRequest.php 6KB
LiveChannel.php 6KB
CreateUploadVideoRequest.php 6KB
ListObjectsResultTest.php 6KB
MultipartUpload.php 6KB
GetPlayInfoRequest.php 5KB
CreateUploadAttachedMediaRequest.php 5KB
LocationService.php 5KB
SetMessageCallbackRequest.php 5KB
ListMultipartUploadResultTest.php 5KB
Signature.php 5KB
CorsConfigTest.php 5KB
RpcAcsRequest.php 5KB
uploadVideo.php 5KB
Bucket.php 5KB
LifecycleConfigTest.php 5KB
CreateUploadImageRequest.php 4KB
UpdateVideoInfoRequest.php 4KB
ListLiveRecordVideoRequest.php 4KB
DescribeVodRefreshTasksRequest.php 4KB
SearchMediaRequest.php 4KB
Result.php 4KB
SubmitSnapshotJobRequest.php 4KB
ProduceEditingProjectVideoRequest.php 4KB
RamRoleArnService.php 4KB
UploadVideoRequest.php 4KB
ContentTypeTest.php 4KB
GetVideoListRequest.php 4KB
SearchEditingProjectRequest.php 4KB
OssClientBucketTest.php 4KB
UploadMediaByURLRequest.php 4KB
OssClientSignatureTest.php 4KB
HttpHelper.php 4KB
UploadAttachedMediaRequest.php 4KB
BucketLifecycle.php 4KB
SubmitTranscodeJobsRequest.php 3KB
CorsRule.php 3KB
UpdateEditingProjectRequest.php 3KB
AddEditingProjectRequest.php 3KB
Credential.php 3KB
UploadImageRequest.php 3KB
OssClientImageTest.php 3KB
GetMezzanineInfoRequest.php 3KB
Callback.php 3KB
BucketReferer.php 3KB
UpdateAppInfoRequest.php 3KB
DeleteImageRequest.php 3KB
ListSnapshotsRequest.php 3KB
ListBucketsResultTest.php 3KB
Image.php 3KB
ListTranscodeTaskRequest.php 3KB
SubmitAIJobRequest.php 3KB
BucketCors.php 3KB
ListObjectsResult.php 3KB
CorsConfig.php 3KB
UpdateTranscodeTemplateGroupRequest.php 3KB
GetCategoriesRequest.php 3KB
LiveChannelConfig.php 3KB
OssClientRestoreObjectTest.php 3KB
EcsRamRoleService.php 3KB
MoveAppResourceRequest.php 3KB
GetAttachedMediaInfoRequest.php 3KB
DeleteMultipartUploadRequest.php 3KB
RegisterMediaRequest.php 3KB
OssClientBucketCorsTest.php 3KB
InteTest.php 3KB
AddVodTemplateRequest.php 3KB
DetachAppPolicyFromIdentityRequest.php 3KB
BucketLogging.php 3KB
AttachAppPolicyToIdentityRequest.php 3KB
GetVideoPlayAuthRequest.php 3KB
GetEditingProjectMaterialsRequest.php 3KB
ListMultipartUploadInfo.php 3KB
ListAppInfoRequest.php 3KB
RamRoleArnCredential.php 3KB
共 306 条
- 1
- 2
- 3
- 4
资源评论
- bug妹子•Jbb2023-08-15果断支持这个资源,资源解决了当前遇到的问题,给了新的灵感,感谢分享~
reg183
- 粉丝: 1811
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功