<?php use OSS\OssClient; require_once './autoload.php'; // test $bucket = "在阿里雲設置的bucket名字(這里舉例叫testbucket)"; $accessKeyId = "阿里雲Access Key ID"; ; $accessKeySecret = "阿里雲Access Key Secret "; // <您選定的OSS數據中心訪問域名,例如oss-cn-hangzhou.aliyuncs.com> // 如果需要用圖片處理功能那么就用圖片數據中心域名,且需要在bucket里面設置開啟圖片服務 // oss-cn-hongkong.aliyuncs.com $endpoint = "img-cn-hongkong.aliyuncs.com"; try { $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); // $object = "te"; // $content = "Hello, OSS!"; // 上傳的文件內容 // $ossClient->putObject($bucket, $object, $content); // $object = "test.png"; // $filePath = 'D:/phpStudy/WWW/oss/' . $object; // $ossClient->uploadFile($bucket, $object, $filePath); $object = 'message/' . rand(10000, 99999) . '.png'; $content = file_get_contents('./test.png'); $ossClient->putObject($bucket, $object, $content); // URL: http://adtuu-test.oss-cn-hongkong.aliyuncs.com/message/67142.png // 圖片訪問: // 比如想按照等比縮放到原來的一半大小,那么在URL后面加上@50p // URL: http://testbucket.img-cn-hongkong.aliyuncs.com/message/67142.png@50p echo 'URL: http://testbucket.img-cn-hongkong.aliyuncs.com/' . $object, '<BR />'; echo 'URL: http://testbucket.oss-cn-hongkong.aliyuncs.com/' . $object; } catch (OssException $e) { print $e->getMessage(); }