<?php use OSSOssClient; 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(); }