PHP使用签名URL对阿里云对象存储进行临时授权
PHP使用签名URL对阿里云对象存储进行临时授权,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php require_once __DIR__ . '/aliyun/oss/autoload.php'; use OSS\OssClient; use OSS\Core\OssException; $accessKeyId = "yourAccessKeyId"; $accessKeySecret = "yourAccessKeySecret"; $endpoint = "oss-cn-beijing.aliyuncs.com"; $bucket= "examplebucket"; $object = "exampledir/Rihanna - Rude Boy.mp3"; //填写不包含Bucket名称在内的Object完整路径 $timeout = 600; //设置签名URL的有效时长为600秒。 try { $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); $options = array( //填写Object的versionId(这里会报错,可能sdk版本问题) //$ossClient::OSS_VERSION_ID=>"CAEQEhiBgIDmgPf8mxgiIDA1YjZlNDIxY2ZmMzQ1MmU5MTM1Y2M4Yzk4NjIx****" ); //生成签名URL。 $signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options); printf("%s", $signedUrl); } catch(OssException $e) { printf("%s", $e->getMessage()); } ?> |
阿里帮助中心:
首页>对象存储 OSS>SDK示例>PHP>PHP授权访问
https://help.aliyun.com/document_detail/32106.html