騰訊雲 對象存儲V5版本 文檔地址:https://github.com/tencentyun/cos-php-sdk-v5php
調用簡單文件上傳方法:git
返回數據以下github
Array ( [data:protected] => Array ( [Expiration] => [ETag] => "ed076287532e86365e841e92bfc50d8c" [ServerSideEncryption] => AES256 [VersionId] => [SSECustomerAlgorithm] => [SSECustomerKeyMD5] => [SSEKMSKeyId] => [RequestCharged] => [RequestId] => NWE3Yzg0M2NfOTcyMjViNjRfYTE1YV8xNTQzYTY= [ObjectURL] => http://testbucket-1252448703.cos.cn-south.myqcloud.com/11%2F%2F32%2F%2F43 ) )
獲取返回數據中 ObjectURL 參數的值得方法以下 app
上傳本地文件 #putObject try { $result = $cosClient->putObject(array( //bucket的命名規則爲{name}-{appid} ,此處填寫的存儲桶名稱必須爲此格式 'Bucket' => 'testbucket-125000000', 'Key' => 'string', 'Body' => fopen('./hello.txt', 'rb'), 'CacheControl' => 'string', 'ContentDisposition' => 'string', 'ContentEncoding' => 'string', 'ContentLanguage' => 'string', 'ContentLength' => integer, 'ContentType' => 'string', 'Expires' => 'mixed type: string (date format)|int (unix timestamp)|\DateTime', 'GrantFullControl' => 'string', 'GrantRead' => 'string', 'GrantWrite' => 'string', 'Metadata' => array( 'string' => 'string', ), 'StorageClass' => 'string', )); print_r($result); print_r(urldecode($result->get('ObjectURL'))); } catch (\Exception $e) { echo "$e\n"; }
獲取返回的url連接的代碼爲:
print_r(urldecode($result->get('ObjectURL')));
如若使用的是文件流方式上傳,獲取返回的url連接代碼爲:print_r(urldecode($result->get('Location')));