You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
168
vendor/oss-sdk/samples/Bucket.php
vendored
Executable file
168
vendor/oss-sdk/samples/Bucket.php
vendored
Executable file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
//******************************* Simple Usage****************************************************************
|
||||
|
||||
// Create a bucket
|
||||
$ossClient->createBucket($bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
|
||||
Common::println("bucket $bucket created");
|
||||
|
||||
// Check whether a bucket exists
|
||||
$doesExist = $ossClient->doesBucketExist($bucket);
|
||||
Common::println("bucket $bucket exist? " . ($doesExist ? "yes" : "no"));
|
||||
|
||||
// Get the bucket list
|
||||
$bucketListInfo = $ossClient->listBuckets();
|
||||
|
||||
// Set bucket ACL
|
||||
$ossClient->putBucketAcl($bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
|
||||
Common::println("bucket $bucket acl put");
|
||||
// Get bucket ACL
|
||||
$acl = $ossClient->getBucketAcl($bucket);
|
||||
Common::println("bucket $bucket acl get: " . $acl);
|
||||
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
createBucket($ossClient, $bucket);
|
||||
doesBucketExist($ossClient, $bucket);
|
||||
deleteBucket($ossClient, $bucket);
|
||||
putBucketAcl($ossClient, $bucket);
|
||||
getBucketAcl($ossClient, $bucket);
|
||||
listBuckets($ossClient);
|
||||
|
||||
/**
|
||||
* Create a new bucket
|
||||
* acl indicates the access permission of a bucket, including: private, public-read-only/private-read-write, and public read-write.
|
||||
* Private indicates that only the bucket owner or authorized users can access the data..
|
||||
* The three permissions are separately defined by (OssClient::OSS_ACL_TYPE_PRIVATE,OssClient::OSS_ACL_TYPE_PUBLIC_READ, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE)
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to create
|
||||
* @return null
|
||||
*/
|
||||
function createBucket($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->createBucket($bucket, OssClient::OSS_ACL_TYPE_PUBLIC_READ_WRITE);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a bucket exists.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
*/
|
||||
function doesBucketExist($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$res = $ossClient->doesBucketExist($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
if ($res === true) {
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": FAILED" . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a bucket. If the bucket is not empty, the deletion fails.
|
||||
* A bucket which is not empty indicates that it does not contain any objects or parts that are not completely uploaded during multipart upload
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket Name of the bucket to delete
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucket($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->deleteBucket($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bucket ACL
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putBucketAcl($ossClient, $bucket)
|
||||
{
|
||||
$acl = OssClient::OSS_ACL_TYPE_PRIVATE;
|
||||
try {
|
||||
$ossClient->putBucketAcl($bucket, $acl);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get bucket ACL
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketAcl($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$res = $ossClient->getBucketAcl($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print('acl: ' . $res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all buckets
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @return null
|
||||
*/
|
||||
function listBuckets($ossClient)
|
||||
{
|
||||
$bucketList = null;
|
||||
try {
|
||||
$bucketListInfo = $ossClient->listBuckets();
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
$bucketList = $bucketListInfo->getBucketList();
|
||||
foreach ($bucketList as $bucket) {
|
||||
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreatedate() . "\n");
|
||||
}
|
||||
}
|
108
vendor/oss-sdk/samples/BucketCors.php
vendored
Executable file
108
vendor/oss-sdk/samples/BucketCors.php
vendored
Executable file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\CorsConfig;
|
||||
use OSS\Model\CorsRule;
|
||||
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = Common::getBucketName();
|
||||
|
||||
|
||||
//******************************* Simple usage****************************************************************
|
||||
|
||||
// Set cors configuration
|
||||
$corsConfig = new CorsConfig();
|
||||
$rule = new CorsRule();
|
||||
$rule->addAllowedHeader("x-oss-header");
|
||||
$rule->addAllowedOrigin("http://www.b.com");
|
||||
$rule->addAllowedMethod("POST");
|
||||
$rule->setMaxAgeSeconds(10);
|
||||
$corsConfig->addRule($rule);
|
||||
$ossClient->putBucketCors($bucket, $corsConfig);
|
||||
Common::println("bucket $bucket corsConfig created:" . $corsConfig->serializeToXml());
|
||||
|
||||
// Get cors configuration
|
||||
$corsConfig = $ossClient->getBucketCors($bucket);
|
||||
Common::println("bucket $bucket corsConfig fetched:" . $corsConfig->serializeToXml());
|
||||
|
||||
// Delete cors configuration
|
||||
$ossClient->deleteBucketCors($bucket);
|
||||
Common::println("bucket $bucket corsConfig deleted");
|
||||
|
||||
//******************************* For complete usage, see the following functions *****************************************************
|
||||
|
||||
putBucketCors($ossClient, $bucket);
|
||||
getBucketCors($ossClient, $bucket);
|
||||
deleteBucketCors($ossClient, $bucket);
|
||||
getBucketCors($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set bucket cores
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putBucketCors($ossClient, $bucket)
|
||||
{
|
||||
$corsConfig = new CorsConfig();
|
||||
$rule = new CorsRule();
|
||||
$rule->addAllowedHeader("x-oss-header");
|
||||
$rule->addAllowedOrigin("http://www.b.com");
|
||||
$rule->addAllowedMethod("POST");
|
||||
$rule->setMaxAgeSeconds(10);
|
||||
$corsConfig->addRule($rule);
|
||||
|
||||
try {
|
||||
$ossClient->putBucketCors($bucket, $corsConfig);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and print the cors configuration of a bucket
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketCors($ossClient, $bucket)
|
||||
{
|
||||
$corsConfig = null;
|
||||
try {
|
||||
$corsConfig = $ossClient->getBucketCors($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print($corsConfig->serializeToXml() . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all cors configuraiton of a bucket
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketCors($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->deleteBucketCors($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
109
vendor/oss-sdk/samples/BucketLifecycle.php
vendored
Executable file
109
vendor/oss-sdk/samples/BucketLifecycle.php
vendored
Executable file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\LifecycleAction;
|
||||
use OSS\Model\LifecycleConfig;
|
||||
use OSS\Model\LifecycleRule;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage *******************************************************
|
||||
|
||||
// Set lifecycle configuration
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction("Expiration", "Days", 3);
|
||||
$lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
$ossClient->putBucketLifecycle($bucket, $lifecycleConfig);
|
||||
Common::println("bucket $bucket lifecycleConfig created:" . $lifecycleConfig->serializeToXml());
|
||||
|
||||
// Get lifecycle configuration
|
||||
$lifecycleConfig = $ossClient->getBucketLifecycle($bucket);
|
||||
Common::println("bucket $bucket lifecycleConfig fetched:" . $lifecycleConfig->serializeToXml());
|
||||
|
||||
// Delete bucket lifecycle configuration
|
||||
$ossClient->deleteBucketLifecycle($bucket);
|
||||
Common::println("bucket $bucket lifecycleConfig deleted");
|
||||
|
||||
|
||||
//***************************** For complete usage, see the following functions ***********************************************
|
||||
|
||||
putBucketLifecycle($ossClient, $bucket);
|
||||
getBucketLifecycle($ossClient, $bucket);
|
||||
deleteBucketLifecycle($ossClient, $bucket);
|
||||
getBucketLifecycle($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set bucket lifecycle configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putBucketLifecycle($ossClient, $bucket)
|
||||
{
|
||||
$lifecycleConfig = new LifecycleConfig();
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction(OssClient::OSS_LIFECYCLE_EXPIRATION, OssClient::OSS_LIFECYCLE_TIMING_DAYS, 3);
|
||||
$lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
$actions = array();
|
||||
$actions[] = new LifecycleAction(OssClient::OSS_LIFECYCLE_EXPIRATION, OssClient::OSS_LIFECYCLE_TIMING_DATE, '2022-10-12T00:00:00.000Z');
|
||||
$lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
|
||||
$lifecycleConfig->addRule($lifecycleRule);
|
||||
try {
|
||||
$ossClient->putBucketLifecycle($bucket, $lifecycleConfig);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bucket lifecycle configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketLifecycle($ossClient, $bucket)
|
||||
{
|
||||
$lifecycleConfig = null;
|
||||
try {
|
||||
$lifecycleConfig = $ossClient->getBucketLifecycle($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print($lifecycleConfig->serializeToXml() . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete bucket lifecycle configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketLifecycle($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->deleteBucketLifecycle($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
95
vendor/oss-sdk/samples/BucketLogging.php
vendored
Executable file
95
vendor/oss-sdk/samples/BucketLogging.php
vendored
Executable file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//*******************************Simple Usage ***************************************************************
|
||||
|
||||
// Set bucket access logging rules. Access logs are stored under the same bucket with a 'access.log' prefix.
|
||||
$ossClient->putBucketLogging($bucket, $bucket, "access.log", array());
|
||||
Common::println("bucket $bucket lifecycleConfig created");
|
||||
|
||||
// Get bucket access logging rules
|
||||
$loggingConfig = $ossClient->getBucketLogging($bucket, array());
|
||||
Common::println("bucket $bucket lifecycleConfig fetched:" . $loggingConfig->serializeToXml());
|
||||
|
||||
// Delete bucket access logging rules
|
||||
$loggingConfig = $ossClient->getBucketLogging($bucket, array());
|
||||
Common::println("bucket $bucket lifecycleConfig deleted");
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putBucketLogging($ossClient, $bucket);
|
||||
getBucketLogging($ossClient, $bucket);
|
||||
deleteBucketLogging($ossClient, $bucket);
|
||||
getBucketLogging($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set bucket logging configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putBucketLogging($ossClient, $bucket)
|
||||
{
|
||||
$option = array();
|
||||
// Access logs are stored in the same bucket.
|
||||
$targetBucket = $bucket;
|
||||
$targetPrefix = "access.log";
|
||||
|
||||
try {
|
||||
$ossClient->putBucketLogging($bucket, $targetBucket, $targetPrefix, $option);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bucket logging configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketLogging($ossClient, $bucket)
|
||||
{
|
||||
$loggingConfig = null;
|
||||
$options = array();
|
||||
try {
|
||||
$loggingConfig = $ossClient->getBucketLogging($bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print($loggingConfig->serializeToXml() . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete bucket logging configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketLogging($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->deleteBucketLogging($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
101
vendor/oss-sdk/samples/BucketReferer.php
vendored
Executable file
101
vendor/oss-sdk/samples/BucketReferer.php
vendored
Executable file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use \OSS\Model\RefererConfig;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage ****************************************************************
|
||||
|
||||
// Set referer whitelist
|
||||
$refererConfig = new RefererConfig();
|
||||
$refererConfig->setAllowEmptyReferer(true);
|
||||
$refererConfig->addReferer("www.aliiyun.com");
|
||||
$refererConfig->addReferer("www.aliiyuncs.com");
|
||||
$ossClient->putBucketReferer($bucket, $refererConfig);
|
||||
Common::println("bucket $bucket refererConfig created:" . $refererConfig->serializeToXml());
|
||||
// Get referer whitelist
|
||||
$refererConfig = $ossClient->getBucketReferer($bucket);
|
||||
Common::println("bucket $bucket refererConfig fetched:" . $refererConfig->serializeToXml());
|
||||
|
||||
// Delete referrer whitelist
|
||||
$refererConfig = new RefererConfig();
|
||||
$ossClient->putBucketReferer($bucket, $refererConfig);
|
||||
Common::println("bucket $bucket refererConfig deleted");
|
||||
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putBucketReferer($ossClient, $bucket);
|
||||
getBucketReferer($ossClient, $bucket);
|
||||
deleteBucketReferer($ossClient, $bucket);
|
||||
getBucketReferer($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Set bucket referer configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putBucketReferer($ossClient, $bucket)
|
||||
{
|
||||
$refererConfig = new RefererConfig();
|
||||
$refererConfig->setAllowEmptyReferer(true);
|
||||
$refererConfig->addReferer("www.aliiyun.com");
|
||||
$refererConfig->addReferer("www.aliiyuncs.com");
|
||||
try {
|
||||
$ossClient->putBucketReferer($bucket, $refererConfig);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bucket referer configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketReferer($ossClient, $bucket)
|
||||
{
|
||||
$refererConfig = null;
|
||||
try {
|
||||
$refererConfig = $ossClient->getBucketReferer($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print($refererConfig->serializeToXml() . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete bucket referer configuration
|
||||
* Referer whitelist cannot be directly deleted. So use a empty one to overwrite it.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketReferer($ossClient, $bucket)
|
||||
{
|
||||
$refererConfig = new RefererConfig();
|
||||
try {
|
||||
$ossClient->putBucketReferer($bucket, $refererConfig);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
92
vendor/oss-sdk/samples/BucketWebsite.php
vendored
Executable file
92
vendor/oss-sdk/samples/BucketWebsite.php
vendored
Executable file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Model\WebsiteConfig;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage ***************************************************************
|
||||
|
||||
// Set bucket static website configuration
|
||||
$websiteConfig = new WebsiteConfig("index.html", "error.html");
|
||||
$ossClient->putBucketWebsite($bucket, $websiteConfig);
|
||||
Common::println("bucket $bucket websiteConfig created:" . $websiteConfig->serializeToXml());
|
||||
|
||||
// Get bucket static website configuration
|
||||
$websiteConfig = $ossClient->getBucketWebsite($bucket);
|
||||
Common::println("bucket $bucket websiteConfig fetched:" . $websiteConfig->serializeToXml());
|
||||
|
||||
// Delete bucket static website configuration
|
||||
$ossClient->deleteBucketWebsite($bucket);
|
||||
Common::println("bucket $bucket websiteConfig deleted");
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
putBucketWebsite($ossClient, $bucket);
|
||||
getBucketWebsite($ossClient, $bucket);
|
||||
deleteBucketWebsite($ossClient, $bucket);
|
||||
getBucketWebsite($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Sets bucket static website configuration
|
||||
*
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket string bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putBucketWebsite($ossClient, $bucket)
|
||||
{
|
||||
$websiteConfig = new WebsiteConfig("index.html", "error.html");
|
||||
try {
|
||||
$ossClient->putBucketWebsite($bucket, $websiteConfig);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bucket static website configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getBucketWebsite($ossClient, $bucket)
|
||||
{
|
||||
$websiteConfig = null;
|
||||
try {
|
||||
$websiteConfig = $ossClient->getBucketWebsite($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
print($websiteConfig->serializeToXml() . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete bucket static website configuration
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteBucketWebsite($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->deleteBucketWebsite($bucket);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
83
vendor/oss-sdk/samples/Callback.php
vendored
Executable file
83
vendor/oss-sdk/samples/Callback.php
vendored
Executable file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage ***************************************************************
|
||||
|
||||
/** putObject Upload content to an OSS file using callback.
|
||||
* The callbackurl specifies the server url for the request callback.
|
||||
* The callbackbodytype can be application/json or application/x-www-form-urlencoded,the optional parameters,the default for the application/x - WWW - form - urlencoded
|
||||
* Users can choose not to set OSS_BACK_VAR
|
||||
*/
|
||||
$url =
|
||||
'{
|
||||
"callbackUrl":"callback.oss-demo.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"bucket=${bucket}&object=${object}&etag=${etag}&size=${size}&mimeType=${mimeType}&imageInfo.height=${imageInfo.height}&imageInfo.width=${imageInfo.width}&imageInfo.format=${imageInfo.format}&my_var1=${x:var1}&my_var2=${x:var2}",
|
||||
"callbackBodyType":"application/x-www-form-urlencoded"
|
||||
|
||||
}';
|
||||
$var =
|
||||
'{
|
||||
"x:var1":"value1",
|
||||
"x:var2":"值2"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $url,
|
||||
OssClient::OSS_CALLBACK_VAR => $var
|
||||
);
|
||||
$result = $ossClient->putObject($bucket, "b.file", "random content", $options);
|
||||
Common::println($result['body']);
|
||||
Common::println($result['info']['http_code']);
|
||||
|
||||
/**
|
||||
* completeMultipartUpload Upload content to an OSS file using callback.
|
||||
* callbackurl specifies the server url for the request callback
|
||||
* The callbackbodytype can be application/json or application/x-www-form-urlencoded,the optional parameters,the default for the application/x - WWW - form - urlencoded
|
||||
* Users can choose not to set OSS_BACK_VAR.
|
||||
*/
|
||||
$object = "multipart-callback-test.txt";
|
||||
$copiedObject = "multipart-callback-test.txt.copied";
|
||||
$ossClient->putObject($bucket, $copiedObject, file_get_contents(__FILE__));
|
||||
|
||||
/**
|
||||
* step 1. Initialize a block upload event, that is, a multipart upload process to get an upload id
|
||||
*/
|
||||
$upload_id = $ossClient->initiateMultipartUpload($bucket, $object);
|
||||
|
||||
/**
|
||||
* step 2. uploadPartCopy
|
||||
*/
|
||||
$copyId = 1;
|
||||
$eTag = $ossClient->uploadPartCopy($bucket, $copiedObject, $bucket, $object, $copyId, $upload_id);
|
||||
$upload_parts[] = array(
|
||||
'PartNumber' => $copyId,
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
$listPartsInfo = $ossClient->listParts($bucket, $object, $upload_id);
|
||||
|
||||
/**
|
||||
* step 3.
|
||||
*/
|
||||
$json =
|
||||
'{
|
||||
"callbackUrl":"callback.oss-demo.com:23450",
|
||||
"callbackHost":"oss-cn-hangzhou.aliyuncs.com",
|
||||
"callbackBody":"{\"mimeType\":${mimeType},\"size\":${size},\"x:var1\":${x:var1},\"x:var2\":${x:var2}}",
|
||||
"callbackBodyType":"application/json"
|
||||
}';
|
||||
$var =
|
||||
'{
|
||||
"x:var1":"value1",
|
||||
"x:var2":"值2"
|
||||
}';
|
||||
$options = array(OssClient::OSS_CALLBACK => $json,
|
||||
OssClient::OSS_CALLBACK_VAR => $var);
|
||||
|
||||
$result = $ossClient->completeMultipartUpload($bucket, $object, $upload_id, $upload_parts, $options);
|
||||
Common::println($result['body']);
|
||||
Common::println($result['info']['http_code']);
|
84
vendor/oss-sdk/samples/Common.php
vendored
Executable file
84
vendor/oss-sdk/samples/Common.php
vendored
Executable file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
if (is_file(__DIR__ . '/../autoload.php')) {
|
||||
require_once __DIR__ . '/../autoload.php';
|
||||
}
|
||||
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
}
|
||||
require_once __DIR__ . '/Config.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class Common
|
||||
*
|
||||
* The Common class for 【Samples/*.php】 used to obtain OssClient instance and other common functions
|
||||
*/
|
||||
class Common
|
||||
{
|
||||
const endpoint = Config::OSS_ENDPOINT;
|
||||
const accessKeyId = Config::OSS_ACCESS_ID;
|
||||
const accessKeySecret = Config::OSS_ACCESS_KEY;
|
||||
const bucket = Config::OSS_TEST_BUCKET;
|
||||
|
||||
/**
|
||||
* Get an OSSClient instance according to config.
|
||||
*
|
||||
* @return OssClient An OssClient instance
|
||||
*/
|
||||
public static function getOssClient()
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(self::accessKeyId, self::accessKeySecret, self::endpoint, false);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return null;
|
||||
}
|
||||
return $ossClient;
|
||||
}
|
||||
|
||||
public static function getBucketName()
|
||||
{
|
||||
return self::bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool function which creates a bucket and exists the process if there are exceptions
|
||||
*/
|
||||
public static function createBucket()
|
||||
{
|
||||
$ossClient = self::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
$bucket = self::getBucketName();
|
||||
$acl = OssClient::OSS_ACL_TYPE_PUBLIC_READ;
|
||||
try {
|
||||
$ossClient->createBucket($bucket, $acl);
|
||||
} catch (OssException $e) {
|
||||
|
||||
$message = $e->getMessage();
|
||||
if (\OSS\Core\OssUtil::startsWith($message, 'http status: 403')) {
|
||||
echo "Please Check your AccessKeyId and AccessKeySecret" . "\n";
|
||||
exit(0);
|
||||
} elseif (strpos($message, "BucketAlreadyExists") !== false) {
|
||||
echo "Bucket already exists. Please check whether the bucket belongs to you, or it was visited with correct endpoint. " . "\n";
|
||||
exit(0);
|
||||
}
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
public static function println($message)
|
||||
{
|
||||
if (!empty($message)) {
|
||||
echo strval($message) . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Common::createBucket();
|
15
vendor/oss-sdk/samples/Config.php
vendored
Executable file
15
vendor/oss-sdk/samples/Config.php
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Config
|
||||
*
|
||||
* Make configurations required by the sample.
|
||||
* Users can run RunAll.php which runs all the samples after configuring Endpoint, AccessId, and AccessKey.
|
||||
*/
|
||||
final class Config
|
||||
{
|
||||
const OSS_ACCESS_ID = 'update me';
|
||||
const OSS_ACCESS_KEY = 'update me';
|
||||
const OSS_ENDPOINT = 'update me';
|
||||
const OSS_TEST_BUCKET = 'update me';
|
||||
}
|
87
vendor/oss-sdk/samples/Image.php
vendored
Executable file
87
vendor/oss-sdk/samples/Image.php
vendored
Executable file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
|
||||
$bucketName = Common::getBucketName();
|
||||
$object = "example.jpg";
|
||||
$ossClient = Common::getOssClient();
|
||||
$download_file = "download.jpg";
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage ***************************************************************
|
||||
|
||||
// Upload example.jpg to the specified bucket and rename it to $object.
|
||||
$ossClient->uploadFile($bucketName, $object, "example.jpg");
|
||||
|
||||
// Image resize
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/resize,m_fixed,h_100,w_100", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("imageResize",$download_file);
|
||||
|
||||
// Image crop
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/crop,w_100,h_100,x_100,y_100,r_1", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("iamgeCrop", $download_file);
|
||||
|
||||
// Image rotate
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/rotate,90", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("imageRotate", $download_file);
|
||||
|
||||
// Image sharpen
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/sharpen,100", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("imageSharpen", $download_file);
|
||||
|
||||
// Add watermark into a image
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/watermark,text_SGVsbG8g5Zu-54mH5pyN5YqhIQ", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("imageWatermark", $download_file);
|
||||
|
||||
// Image format convertion
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/format,png", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("imageFormat", $download_file);
|
||||
|
||||
// Get image information
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $download_file,
|
||||
OssClient::OSS_PROCESS => "image/info", );
|
||||
$ossClient->getObject($bucketName, $object, $options);
|
||||
printImage("imageInfo", $download_file);
|
||||
|
||||
|
||||
/**
|
||||
* Generate a signed url which could be used in browser to access the object. The expiration time is 1 hour.
|
||||
*/
|
||||
$timeout = 3600;
|
||||
$options = array(
|
||||
OssClient::OSS_PROCESS => "image/resize,m_lfit,h_100,w_100",
|
||||
);
|
||||
$signedUrl = $ossClient->signUrl($bucketName, $object, $timeout, "GET", $options);
|
||||
Common::println("rtmp url: \n" . $signedUrl);
|
||||
|
||||
// Finally delete the $object uploaded.
|
||||
$ossClient->deleteObject($bucketName, $object);
|
||||
|
||||
function printImage($func, $imageFile)
|
||||
{
|
||||
$array = getimagesize($imageFile);
|
||||
Common::println("$func, image width: " . $array[0]);
|
||||
Common::println("$func, image height: " . $array[1]);
|
||||
Common::println("$func, image type: " . ($array[2] === 2 ? 'jpg' : 'png'));
|
||||
Common::println("$func, image size: " . ceil(filesize($imageFile)));
|
||||
}
|
131
vendor/oss-sdk/samples/LiveChannel.php
vendored
Executable file
131
vendor/oss-sdk/samples/LiveChannel.php
vendored
Executable file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Model\LiveChannelConfig;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage *******************************************************
|
||||
|
||||
/**
|
||||
* Create a Live Channel
|
||||
* The live channel's name is test_rtmp_live.
|
||||
* The play url file is named as test.m3u8, which includes 3 ts files.
|
||||
* The time period of each file is 5 seconds.(It is recommneded value only for demo purpose, the actual period depends on the key frame.)
|
||||
*
|
||||
*/
|
||||
$config = new LiveChannelConfig(array(
|
||||
'description' => 'live channel test',
|
||||
'type' => 'HLS',
|
||||
'fragDuration' => 10,
|
||||
'fragCount' => 5,
|
||||
'playListName' => 'hello.m3u8'
|
||||
));
|
||||
$info = $ossClient->putBucketLiveChannel($bucket, 'test_rtmp_live', $config);
|
||||
Common::println("bucket $bucket liveChannel created:\n" .
|
||||
"live channel name: ". $info->getName() . "\n" .
|
||||
"live channel description: ". $info->getDescription() . "\n" .
|
||||
"publishurls: ". $info->getPublishUrls()[0] . "\n" .
|
||||
"playurls: ". $info->getPlayUrls()[0] . "\n");
|
||||
|
||||
/**
|
||||
* You can use listBucketLiveChannels to list and manage all existing live channels.
|
||||
* Prefix can be used to filter listed live channels by prefix.
|
||||
* Max_keys indicates the maximum numbers of live channels that can be listed in an iterator at one time. Its value is 1000 in maximum and 100 by default.
|
||||
*/
|
||||
$list = $ossClient->listBucketLiveChannels($bucket);
|
||||
Common::println("bucket $bucket listLiveChannel:\n" .
|
||||
"list live channel prefix: ". $list->getPrefix() . "\n" .
|
||||
"list live channel marker: ". $list->getMarker() . "\n" .
|
||||
"list live channel maxkey: ". $list->getMaxKeys() . "\n" .
|
||||
"list live channel IsTruncated: ". $list->getIsTruncated() . "\n" .
|
||||
"list live channel getNextMarker: ". $list->getNextMarker() . "\n");
|
||||
|
||||
foreach($list->getChannelList() as $list)
|
||||
{
|
||||
Common::println("bucket $bucket listLiveChannel:\n" .
|
||||
"list live channel IsTruncated: ". $list->getName() . "\n" .
|
||||
"list live channel Description: ". $list->getDescription() . "\n" .
|
||||
"list live channel Status: ". $list->getStatus() . "\n" .
|
||||
"list live channel getNextMarker: ". $list->getLastModified() . "\n");
|
||||
}
|
||||
/**
|
||||
* Obtain the play_url (url used for rtmp stream pushing.
|
||||
* If the the bucket is not globally readable and writable,
|
||||
* the url must be signed as shown in the following.) and pulish_url (the url included in the m3u8 file generated in stream pushing) used to push streams.
|
||||
*/
|
||||
$play_url = $ossClient->signRtmpUrl($bucket, "test_rtmp_live", 3600, array('params' => array('playlistName' => 'playlist.m3u8')));
|
||||
Common::println("bucket $bucket rtmp url: \n" . $play_url);
|
||||
$play_url = $ossClient->signRtmpUrl($bucket, "test_rtmp_live", 3600);
|
||||
Common::println("bucket $bucket rtmp url: \n" . $play_url);
|
||||
|
||||
/**
|
||||
* If you want to disable a created live channel (disable the pushing streaming or do not allow stream pushing to an IP address), call putLiveChannelStatus to change the channel status to "Disabled".
|
||||
* If you want to enable a disabled live channel, call PutLiveChannelStatus to chanage the channel status to "Enabled".
|
||||
*/
|
||||
$resp = $ossClient->putLiveChannelStatus($bucket, "test_rtmp_live", "enabled");
|
||||
|
||||
/**
|
||||
* You can callLiveChannelInfo to get the information about a live channel.
|
||||
*/
|
||||
$info = $ossClient->getLiveChannelInfo($bucket, 'test_rtmp_live');
|
||||
Common::println("bucket $bucket LiveChannelInfo:\n" .
|
||||
"live channel info description: ". $info->getDescription() . "\n" .
|
||||
"live channel info status: ". $info->getStatus() . "\n" .
|
||||
"live channel info type: ". $info->getType() . "\n" .
|
||||
"live channel info fragDuration: ". $info->getFragDuration() . "\n" .
|
||||
"live channel info fragCount: ". $info->getFragCount() . "\n" .
|
||||
"live channel info playListName: ". $info->getPlayListName() . "\n");
|
||||
|
||||
/**
|
||||
* Gets the historical pushing streaming records by calling getLiveChannelHistory. Now the max records to return is 10.
|
||||
*/
|
||||
$history = $ossClient->getLiveChannelHistory($bucket, "test_rtmp_live");
|
||||
if (count($history->getLiveRecordList()) != 0)
|
||||
{
|
||||
foreach($history->getLiveRecordList() as $recordList)
|
||||
{
|
||||
Common::println("bucket $bucket liveChannelHistory:\n" .
|
||||
"live channel history startTime: ". $recordList->getStartTime() . "\n" .
|
||||
"live channel history endTime: ". $recordList->getEndTime() . "\n" .
|
||||
"live channel history remoteAddr: ". $recordList->getRemoteAddr() . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the live channel's status by calling getLiveChannelStatus.
|
||||
* If the live channel is receiving the pushing stream, all attributes in stat_result are valid.
|
||||
* If the live channel is idle or disabled, then the status is idle or Disabled and other attributes have no meaning.
|
||||
*/
|
||||
$status = $ossClient->getLiveChannelStatus($bucket, "test_rtmp_live");
|
||||
Common::println("bucket $bucket listLiveChannel:\n" .
|
||||
"live channel status status: ". $status->getStatus() . "\n" .
|
||||
"live channel status ConnectedTime: ". $status->getConnectedTime() . "\n" .
|
||||
"live channel status VideoWidth: ". $status->getVideoWidth() . "\n" .
|
||||
"live channel status VideoHeight: ". $status->getVideoHeight() . "\n" .
|
||||
"live channel status VideoFrameRate: ". $status->getVideoFrameRate() . "\n" .
|
||||
"live channel status VideoBandwidth: ". $status->getVideoBandwidth() . "\n" .
|
||||
"live channel status VideoCodec: ". $status->getVideoCodec() . "\n" .
|
||||
"live channel status AudioBandwidth: ". $status->getAudioBandwidth() . "\n" .
|
||||
"live channel status AudioSampleRate: ". $status->getAudioSampleRate() . "\n" .
|
||||
"live channel status AdioCodec: ". $status->getAudioCodec() . "\n");
|
||||
|
||||
/**
|
||||
* If you want to generate a play url from the ts files generated from pushing streaming, call postVodPlayList.
|
||||
* Specify the start time to 60 seconds before the current time and the end time to the current time, which means that a video of 60 seconds is generated.
|
||||
* The playlist file is specified to “vod_playlist.m3u8”, which means that a palylist file named vod_playlist.m3u8 is created after the interface is called.
|
||||
*/
|
||||
$current_time = time();
|
||||
$ossClient->postVodPlaylist($bucket,
|
||||
"test_rtmp_live", "vod_playlist.m3u8",
|
||||
array('StartTime' => $current_time - 60,
|
||||
'EndTime' => $current_time)
|
||||
);
|
||||
|
||||
/**
|
||||
* Call delete_live_channel to delete a live channel if it will no longer be in used.
|
||||
*/
|
||||
$ossClient->deleteBucketLiveChannel($bucket, "test_rtmp_live");
|
182
vendor/oss-sdk/samples/MultipartUpload.php
vendored
Executable file
182
vendor/oss-sdk/samples/MultipartUpload.php
vendored
Executable file
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple usage ***************************************************************
|
||||
|
||||
/**
|
||||
* See the putObjectByRawAPis usage in complete example to check out basic multipart upload APIs which can be used as resumable upload.
|
||||
*/
|
||||
|
||||
// Upload a file using the multipart upload interface, which determines to use simple upload or multipart upload based on the file size.
|
||||
$ossClient->multiuploadFile($bucket, "file.php", __FILE__, array());
|
||||
Common::println("local file " . __FILE__ . " is uploaded to the bucket $bucket, file.php");
|
||||
|
||||
|
||||
// Upload local directory's data into target dir
|
||||
$ossClient->uploadDir($bucket, "targetdir", __DIR__);
|
||||
Common::println("local dir " . __DIR__ . " is uploaded to the bucket $bucket, targetdir/");
|
||||
|
||||
|
||||
// List the incomplete multipart uploads
|
||||
$listMultipartUploadInfo = $ossClient->listMultipartUploads($bucket, array());
|
||||
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
multiuploadFile($ossClient, $bucket);
|
||||
putObjectByRawApis($ossClient, $bucket);
|
||||
uploadDir($ossClient, $bucket);
|
||||
listMultipartUploads($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Upload files using multipart upload
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function multiuploadFile($ossClient, $bucket)
|
||||
{
|
||||
$object = "test/multipart-test.txt";
|
||||
$file = __FILE__;
|
||||
$options = array();
|
||||
|
||||
try {
|
||||
$ossClient->multiuploadFile($bucket, $object, $file, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Use basic multipart upload for file upload.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @throws OssException
|
||||
*/
|
||||
function putObjectByRawApis($ossClient, $bucket)
|
||||
{
|
||||
$object = "test/multipart-test.txt";
|
||||
/**
|
||||
* step 1. Initialize a block upload event, that is, a multipart upload process to get an upload id
|
||||
*/
|
||||
try {
|
||||
$uploadId = $ossClient->initiateMultipartUpload($bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": initiateMultipartUpload FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": initiateMultipartUpload OK" . "\n");
|
||||
/*
|
||||
* step 2. Upload parts
|
||||
*/
|
||||
$partSize = 10 * 1024 * 1024;
|
||||
$uploadFile = __FILE__;
|
||||
$uploadFileSize = filesize($uploadFile);
|
||||
$pieces = $ossClient->generateMultiuploadParts($uploadFileSize, $partSize);
|
||||
$responseUploadPart = array();
|
||||
$uploadPosition = 0;
|
||||
$isCheckMd5 = true;
|
||||
foreach ($pieces as $i => $piece) {
|
||||
$fromPos = $uploadPosition + (integer)$piece[$ossClient::OSS_SEEK_TO];
|
||||
$toPos = (integer)$piece[$ossClient::OSS_LENGTH] + $fromPos - 1;
|
||||
$upOptions = array(
|
||||
$ossClient::OSS_FILE_UPLOAD => $uploadFile,
|
||||
$ossClient::OSS_PART_NUM => ($i + 1),
|
||||
$ossClient::OSS_SEEK_TO => $fromPos,
|
||||
$ossClient::OSS_LENGTH => $toPos - $fromPos + 1,
|
||||
$ossClient::OSS_CHECK_MD5 => $isCheckMd5,
|
||||
);
|
||||
if ($isCheckMd5) {
|
||||
$contentMd5 = OssUtil::getMd5SumForFile($uploadFile, $fromPos, $toPos);
|
||||
$upOptions[$ossClient::OSS_CONTENT_MD5] = $contentMd5;
|
||||
}
|
||||
//2. Upload each part to OSS
|
||||
try {
|
||||
$responseUploadPart[] = $ossClient->uploadPart($bucket, $object, $uploadId, $upOptions);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": initiateMultipartUpload, uploadPart - part#{$i} FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
printf(__FUNCTION__ . ": initiateMultipartUpload, uploadPart - part#{$i} OK\n");
|
||||
}
|
||||
$uploadParts = array();
|
||||
foreach ($responseUploadPart as $i => $eTag) {
|
||||
$uploadParts[] = array(
|
||||
'PartNumber' => ($i + 1),
|
||||
'ETag' => $eTag,
|
||||
);
|
||||
}
|
||||
/**
|
||||
* step 3. Complete the upload
|
||||
*/
|
||||
try {
|
||||
$ossClient->completeMultipartUpload($bucket, $object, $uploadId, $uploadParts);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": completeMultipartUpload FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
printf(__FUNCTION__ . ": completeMultipartUpload OK\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload by directories
|
||||
*
|
||||
* @param OssClient $ossClient OssClient
|
||||
* @param string $bucket bucket name
|
||||
*
|
||||
*/
|
||||
function uploadDir($ossClient, $bucket)
|
||||
{
|
||||
$localDirectory = ".";
|
||||
$prefix = "samples/codes";
|
||||
try {
|
||||
$ossClient->uploadDir($bucket, $prefix, $localDirectory);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
printf(__FUNCTION__ . ": completeMultipartUpload OK\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ongoing multipart uploads
|
||||
*
|
||||
* @param $ossClient OssClient
|
||||
* @param $bucket string
|
||||
*/
|
||||
function listMultipartUploads($ossClient, $bucket)
|
||||
{
|
||||
$options = array(
|
||||
'max-uploads' => 100,
|
||||
'key-marker' => '',
|
||||
'prefix' => '',
|
||||
'upload-id-marker' => ''
|
||||
);
|
||||
try {
|
||||
$listMultipartUploadInfo = $ossClient->listMultipartUploads($bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": listMultipartUploads FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
printf(__FUNCTION__ . ": listMultipartUploads OK\n");
|
||||
$listUploadInfo = $listMultipartUploadInfo->getUploads();
|
||||
var_dump($listUploadInfo);
|
||||
}
|
518
vendor/oss-sdk/samples/Object.php
vendored
Executable file
518
vendor/oss-sdk/samples/Object.php
vendored
Executable file
@ -0,0 +1,518 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
//******************************* Simple usage ***************************************************************
|
||||
|
||||
// Upload the in-memory string (hi, oss) to an OSS file
|
||||
$result = $ossClient->putObject($bucket, "b.file", "hi, oss");
|
||||
Common::println("b.file is created");
|
||||
Common::println($result['x-oss-request-id']);
|
||||
Common::println($result['etag']);
|
||||
Common::println($result['content-md5']);
|
||||
Common::println($result['body']);
|
||||
|
||||
// Uploads a local file to an OSS file
|
||||
$result = $ossClient->uploadFile($bucket, "c.file", __FILE__);
|
||||
Common::println("c.file is created");
|
||||
Common::println("b.file is created");
|
||||
Common::println($result['x-oss-request-id']);
|
||||
Common::println($result['etag']);
|
||||
Common::println($result['content-md5']);
|
||||
Common::println($result['body']);
|
||||
|
||||
// Download an oss object as an in-memory variable
|
||||
$content = $ossClient->getObject($bucket, "b.file");
|
||||
Common::println("b.file is fetched, the content is: " . $content);
|
||||
|
||||
// Add a symlink to an object
|
||||
$content = $ossClient->putSymlink($bucket, "test-symlink", "b.file");
|
||||
Common::println("test-symlink is created");
|
||||
Common::println($result['x-oss-request-id']);
|
||||
Common::println($result['etag']);
|
||||
|
||||
// Get a symlink
|
||||
$content = $ossClient->getSymlink($bucket, "test-symlink");
|
||||
Common::println("test-symlink refer to : " . $content[OssClient::OSS_SYMLINK_TARGET]);
|
||||
|
||||
// Download an object to a local file.
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => "./c.file.localcopy",
|
||||
);
|
||||
$ossClient->getObject($bucket, "c.file", $options);
|
||||
Common::println("b.file is fetched to the local file: c.file.localcopy");
|
||||
Common::println("b.file is created");
|
||||
|
||||
// Copy an object
|
||||
$result = $ossClient->copyObject($bucket, "c.file", $bucket, "c.file.copy");
|
||||
Common::println("lastModifiedTime: " . $result[0]);
|
||||
Common::println("ETag: " . $result[1]);
|
||||
|
||||
// Check whether an object exists
|
||||
$doesExist = $ossClient->doesObjectExist($bucket, "c.file.copy");
|
||||
Common::println("file c.file.copy exist? " . ($doesExist ? "yes" : "no"));
|
||||
|
||||
// Delete an object
|
||||
$result = $ossClient->deleteObject($bucket, "c.file.copy");
|
||||
Common::println("c.file.copy is deleted");
|
||||
Common::println("b.file is created");
|
||||
Common::println($result['x-oss-request-id']);
|
||||
|
||||
// Check whether an object exists
|
||||
$doesExist = $ossClient->doesObjectExist($bucket, "c.file.copy");
|
||||
Common::println("file c.file.copy exist? " . ($doesExist ? "yes" : "no"));
|
||||
|
||||
// Delete multiple objects in batch
|
||||
$result = $ossClient->deleteObjects($bucket, array("b.file", "c.file"));
|
||||
foreach($result as $object)
|
||||
Common::println($object);
|
||||
|
||||
sleep(2);
|
||||
unlink("c.file.localcopy");
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
listObjects($ossClient, $bucket);
|
||||
listAllObjects($ossClient, $bucket);
|
||||
createObjectDir($ossClient, $bucket);
|
||||
putObject($ossClient, $bucket);
|
||||
uploadFile($ossClient, $bucket);
|
||||
getObject($ossClient, $bucket);
|
||||
getObjectToLocalFile($ossClient, $bucket);
|
||||
copyObject($ossClient, $bucket);
|
||||
modifyMetaForObject($ossClient, $bucket);
|
||||
getObjectMeta($ossClient, $bucket);
|
||||
deleteObject($ossClient, $bucket);
|
||||
deleteObjects($ossClient, $bucket);
|
||||
doesObjectExist($ossClient, $bucket);
|
||||
getSymlink($ossClient, $bucket);
|
||||
putSymlink($ossClient, $bucket);
|
||||
/**
|
||||
* Create a 'virtual' folder
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function createObjectDir($ossClient, $bucket)
|
||||
{
|
||||
try {
|
||||
$ossClient->createObjectDir($bucket, "dir");
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload in-memory data to oss
|
||||
*
|
||||
* Simple upload---upload specified in-memory data to an OSS object
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putObject($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$content = file_get_contents(__FILE__);
|
||||
$options = array();
|
||||
try {
|
||||
$ossClient->putObject($bucket, $object, $content, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uploads a local file to OSS
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function uploadFile($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$filePath = __FILE__;
|
||||
$options = array();
|
||||
|
||||
try {
|
||||
$ossClient->uploadFile($bucket, $object, $filePath, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all files and folders in the bucket.
|
||||
* Note if there's more items than the max-keys specified, the caller needs to use the nextMarker returned as the value for the next call's maker paramter.
|
||||
* Loop through all the items returned from ListObjects.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function listObjects($ossClient, $bucket)
|
||||
{
|
||||
$prefix = 'oss-php-sdk-test/';
|
||||
$delimiter = '/';
|
||||
$nextMarker = '';
|
||||
$maxkeys = 1000;
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
'marker' => $nextMarker,
|
||||
);
|
||||
try {
|
||||
$listObjectInfo = $ossClient->listObjects($bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
$objectList = $listObjectInfo->getObjectList(); // object list
|
||||
$prefixList = $listObjectInfo->getPrefixList(); // directory list
|
||||
if (!empty($objectList)) {
|
||||
print("objectList:\n");
|
||||
foreach ($objectList as $objectInfo) {
|
||||
print($objectInfo->getKey() . "\n");
|
||||
}
|
||||
}
|
||||
if (!empty($prefixList)) {
|
||||
print("prefixList: \n");
|
||||
foreach ($prefixList as $prefixInfo) {
|
||||
print($prefixInfo->getPrefix() . "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all folders and files under the bucket. Use nextMarker repeatedly to get all objects.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function listAllObjects($ossClient, $bucket)
|
||||
{
|
||||
// Create dir/obj 'folder' and put some files into it.
|
||||
for ($i = 0; $i < 100; $i += 1) {
|
||||
$ossClient->putObject($bucket, "dir/obj" . strval($i), "hi");
|
||||
$ossClient->createObjectDir($bucket, "dir/obj" . strval($i));
|
||||
}
|
||||
|
||||
$prefix = 'dir/';
|
||||
$delimiter = '/';
|
||||
$nextMarker = '';
|
||||
$maxkeys = 30;
|
||||
|
||||
while (true) {
|
||||
$options = array(
|
||||
'delimiter' => $delimiter,
|
||||
'prefix' => $prefix,
|
||||
'max-keys' => $maxkeys,
|
||||
'marker' => $nextMarker,
|
||||
);
|
||||
var_dump($options);
|
||||
try {
|
||||
$listObjectInfo = $ossClient->listObjects($bucket, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
// Get the nextMarker, and it would be used as the next call's marker parameter to resume from the last call
|
||||
$nextMarker = $listObjectInfo->getNextMarker();
|
||||
$listObject = $listObjectInfo->getObjectList();
|
||||
$listPrefix = $listObjectInfo->getPrefixList();
|
||||
var_dump(count($listObject));
|
||||
var_dump(count($listPrefix));
|
||||
if ($nextMarker === '') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of an object.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getObject($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$options = array();
|
||||
try {
|
||||
$content = $ossClient->getObject($bucket, $object, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
if (file_get_contents(__FILE__) === $content) {
|
||||
print(__FUNCTION__ . ": FileContent checked OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": FileContent checked FAILED" . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put symlink
|
||||
*
|
||||
* @param OssClient $ossClient The Instance of OssClient
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function putSymlink($ossClient, $bucket)
|
||||
{
|
||||
$symlink = "test-samples-symlink";
|
||||
$object = "test-samples-object";
|
||||
try {
|
||||
$ossClient->putObject($bucket, $object, 'test-content');
|
||||
$ossClient->putSymlink($bucket, $symlink, $object);
|
||||
$content = $ossClient->getObject($bucket, $symlink);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
if ($content == 'test-content') {
|
||||
print(__FUNCTION__ . ": putSymlink checked OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": putSymlink checked FAILED" . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get symlink
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getSymlink($ossClient, $bucket)
|
||||
{
|
||||
$symlink = "test-samples-symlink";
|
||||
$object = "test-samples-object";
|
||||
try {
|
||||
$ossClient->putObject($bucket, $object, 'test-content');
|
||||
$ossClient->putSymlink($bucket, $symlink, $object);
|
||||
$content = $ossClient->getSymlink($bucket, $symlink);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
if ($content[OssClient::OSS_SYMLINK_TARGET]) {
|
||||
print(__FUNCTION__ . ": getSymlink checked OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": getSymlink checked FAILED" . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get_object_to_local_file
|
||||
*
|
||||
* Get object
|
||||
* Download object to a specified file.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getObjectToLocalFile($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$localfile = "upload-test-object-name.txt";
|
||||
$options = array(
|
||||
OssClient::OSS_FILE_DOWNLOAD => $localfile,
|
||||
);
|
||||
|
||||
try {
|
||||
$ossClient->getObject($bucket, $object, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK, please check localfile: 'upload-test-object-name.txt'" . "\n");
|
||||
if (file_get_contents($localfile) === file_get_contents(__FILE__)) {
|
||||
print(__FUNCTION__ . ": FileContent checked OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": FileContent checked FAILED" . "\n");
|
||||
}
|
||||
if (file_exists($localfile)) {
|
||||
unlink($localfile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy object
|
||||
* When the source object is same as the target one, copy operation will just update the metadata.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function copyObject($ossClient, $bucket)
|
||||
{
|
||||
$fromBucket = $bucket;
|
||||
$fromObject = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$toBucket = $bucket;
|
||||
$toObject = $fromObject . '.copy';
|
||||
$options = array();
|
||||
|
||||
try {
|
||||
$ossClient->copyObject($fromBucket, $fromObject, $toBucket, $toObject, $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Object Meta
|
||||
* it leverages the feature of copyObject: when the source object is just the target object, the metadata could be updated via copy
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function modifyMetaForObject($ossClient, $bucket)
|
||||
{
|
||||
$fromBucket = $bucket;
|
||||
$fromObject = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$toBucket = $bucket;
|
||||
$toObject = $fromObject;
|
||||
$copyOptions = array(
|
||||
OssClient::OSS_HEADERS => array(
|
||||
'Cache-Control' => 'max-age=60',
|
||||
'Content-Disposition' => 'attachment; filename="xxxxxx"',
|
||||
),
|
||||
);
|
||||
try {
|
||||
$ossClient->copyObject($fromBucket, $fromObject, $toBucket, $toObject, $copyOptions);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get object meta, that is, getObjectMeta
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getObjectMeta($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
try {
|
||||
$objectMeta = $ossClient->getObjectMeta($bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
if (isset($objectMeta[strtolower('Content-Disposition')]) &&
|
||||
'attachment; filename="xxxxxx"' === $objectMeta[strtolower('Content-Disposition')]
|
||||
) {
|
||||
print(__FUNCTION__ . ": ObjectMeta checked OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": ObjectMeta checked FAILED" . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an object
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteObject($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
try {
|
||||
$ossClient->deleteObject($bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete multiple objects in batch
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function deleteObjects($ossClient, $bucket)
|
||||
{
|
||||
$objects = array();
|
||||
$objects[] = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
$objects[] = "oss-php-sdk-test/upload-test-object-name.txt.copy";
|
||||
try {
|
||||
$ossClient->deleteObjects($bucket, $objects);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an object exists
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
*/
|
||||
function doesObjectExist($ossClient, $bucket)
|
||||
{
|
||||
$object = "oss-php-sdk-test/upload-test-object-name.txt";
|
||||
try {
|
||||
$exist = $ossClient->doesObjectExist($bucket, $object);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
var_dump($exist);
|
||||
}
|
||||
|
13
vendor/oss-sdk/samples/RunAll.php
vendored
Executable file
13
vendor/oss-sdk/samples/RunAll.php
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL | E_NOTICE);
|
||||
|
||||
require_once __DIR__ . '/Bucket.php';
|
||||
require_once __DIR__ . '/BucketCors.php';
|
||||
require_once __DIR__ . '/BucketLifecycle.php';
|
||||
require_once __DIR__ . '/BucketReferer.php';
|
||||
require_once __DIR__ . '/BucketLogging.php';
|
||||
require_once __DIR__ . '/BucketWebsite.php';
|
||||
require_once __DIR__ . '/Signature.php';
|
||||
require_once __DIR__ . '/Object1.php';
|
||||
require_once __DIR__ . '/MultipartUpload.php';
|
142
vendor/oss-sdk/samples/Signature.php
vendored
Executable file
142
vendor/oss-sdk/samples/Signature.php
vendored
Executable file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/Common.php';
|
||||
|
||||
use OSS\Http\RequestCore;
|
||||
use OSS\Http\ResponseCore;
|
||||
use OSS\OssClient;
|
||||
use OSS\Core\OssException;
|
||||
|
||||
$bucket = Common::getBucketName();
|
||||
$ossClient = Common::getOssClient();
|
||||
if (is_null($ossClient)) exit(1);
|
||||
|
||||
//******************************* Simple Usage ***************************************************************
|
||||
|
||||
$ossClient->uploadFile($bucket, "a.file", __FILE__);
|
||||
|
||||
// Generate a signed url for getting an object. The URL can be used in browser directly to download the file.
|
||||
$signedUrl = $ossClient->signUrl($bucket, "a.file", 3600);
|
||||
Common::println($signedUrl);
|
||||
|
||||
// Generate the signed url for putting an object. User can use put method with this url to upload a file to "a.file".
|
||||
$signedUrl = $ossClient->signUrl($bucket, "a.file", "3600", "PUT");
|
||||
Common::println($signedUrl);
|
||||
|
||||
// Generate the signed url for putting an object from local file. The url can be used directly to upload the file to "a.file".
|
||||
$signedUrl = $ossClient->signUrl($bucket, "a.file", 3600, "PUT", array('Content-Type' => 'txt'));
|
||||
Common::println($signedUrl);
|
||||
|
||||
//******************************* For complete usage, see the following functions ****************************************************
|
||||
|
||||
getSignedUrlForPuttingObject($ossClient, $bucket);
|
||||
getSignedUrlForPuttingObjectFromFile($ossClient, $bucket);
|
||||
getSignedUrlForGettingObject($ossClient, $bucket);
|
||||
|
||||
/**
|
||||
* Generate the signed url for getObject() to control read accesses under private privilege
|
||||
*
|
||||
* @param $ossClient OssClient OssClient instance
|
||||
* @param $bucket string bucket name
|
||||
* @return null
|
||||
*/
|
||||
function getSignedUrlForGettingObject($ossClient, $bucket)
|
||||
{
|
||||
$object = "test/test-signature-test-upload-and-download.txt";
|
||||
$timeout = 3600;
|
||||
try {
|
||||
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": signedUrl: " . $signedUrl . "\n");
|
||||
/**
|
||||
* Use similar code to access the object by url, or use browser to access the object.
|
||||
*/
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('GET');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(), $request->get_response_body(), $request->get_response_code());
|
||||
if ($res->isOK()) {
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": FAILED" . "\n");
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the signed url for PutObject to control write accesses under private privilege.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @return null
|
||||
* @throws OssException
|
||||
*/
|
||||
function getSignedUrlForPuttingObject($ossClient, $bucket)
|
||||
{
|
||||
$object = "test/test-signature-test-upload-and-download.txt";
|
||||
$timeout = 3600;
|
||||
$options = NULL;
|
||||
try {
|
||||
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT");
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": signedUrl: " . $signedUrl . "\n");
|
||||
$content = file_get_contents(__FILE__);
|
||||
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('PUT');
|
||||
$request->add_header('Content-Type', '');
|
||||
$request->add_header('Content-Length', strlen($content));
|
||||
$request->set_body($content);
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(),
|
||||
$request->get_response_body(), $request->get_response_code());
|
||||
if ($res->isOK()) {
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": FAILED" . "\n");
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the signed url for PutObject's signed url. User could use the signed url to upload file directly.
|
||||
*
|
||||
* @param OssClient $ossClient OssClient instance
|
||||
* @param string $bucket bucket name
|
||||
* @throws OssException
|
||||
*/
|
||||
function getSignedUrlForPuttingObjectFromFile($ossClient, $bucket)
|
||||
{
|
||||
$file = __FILE__;
|
||||
$object = "test/test-signature-test-upload-and-download.txt";
|
||||
$timeout = 3600;
|
||||
$options = array('Content-Type' => 'txt');
|
||||
try {
|
||||
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
|
||||
} catch (OssException $e) {
|
||||
printf(__FUNCTION__ . ": FAILED\n");
|
||||
printf($e->getMessage() . "\n");
|
||||
return;
|
||||
}
|
||||
print(__FUNCTION__ . ": signedUrl: " . $signedUrl . "\n");
|
||||
|
||||
$request = new RequestCore($signedUrl);
|
||||
$request->set_method('PUT');
|
||||
$request->add_header('Content-Type', 'txt');
|
||||
$request->set_read_file($file);
|
||||
$request->set_read_stream_size(filesize($file));
|
||||
$request->send_request();
|
||||
$res = new ResponseCore($request->get_response_header(),
|
||||
$request->get_response_body(), $request->get_response_code());
|
||||
if ($res->isOK()) {
|
||||
print(__FUNCTION__ . ": OK" . "\n");
|
||||
} else {
|
||||
print(__FUNCTION__ . ": FAILED" . "\n");
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user