通知短信+运营短信,5秒速达,支持群发助手一键发送🚀高效触达和通知客户 广告
## 上传文件 5GB以内文件 ```php composer require aliyuncs/oss-sdk-php <?php use OSS\OssClient; use OSS\Core\OssException; // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。 $accessKeyId = "<yourAccessKeyId>"; $accessKeySecret = "<yourAccessKeySecret>"; // Endpoint以杭州为例,其它Region请按实际情况填写。 $endpoint = "http://oss-cn-hangzhou.aliyuncs.com"; // 设置存储空间名称。 $bucket= "<yourBucketName>"; // 设置文件名称。 $object = "<yourObjectName>"; // <yourLocalFile>由本地文件路径加文件名包括后缀组成,例如/users/local/myfile.txt。 $filePath = "<yourLocalFile>"; try{ $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); $ossClient->uploadFile($bucket, $object, $filePath); } catch(OssException $e) { printf(__FUNCTION__ . ": FAILED\n"); printf($e->getMessage() . "\n"); return; } print(__FUNCTION__ . ": OK" . "\n"); ``` **uploadFile响应结果** 方便查看结构体 ``` <pre>array(15) { ["server"] =&gt; string(9) "AliyunOSS" ["date"] =&gt; string(29) "Sat, 12 Sep 2020 06:25:06 GMT" ["content-length"] =&gt; string(1) "0" ["connection"] =&gt; string(10) "keep-alive" ["x-oss-request-id"] =&gt; string(24) "5F5C69C2ECE57C3031BC002C" ["etag"] =&gt; string(34) ""960FDC5093E0113A3F1B753DF764F0DE"" ["x-oss-hash-crc64ecma"] =&gt; string(20) "10710889662077241995" ["content-md5"] =&gt; string(24) "lg/cUJPgETo/G3U992Tw3g==" ["x-oss-server-time"] =&gt; string(1) "5" ["info"] =&gt; array(38) { ["url"] =&gt; string(78) "https://edk24-com.oss-cn-chengdu.aliyuncs.com/d4f59b691015f8a6f6b40dafef913874" ["content_type"] =&gt; NULL ["http_code"] =&gt; int(200) ["header_size"] =&gt; int(309) ["request_size"] =&gt; int(440) ["filetime"] =&gt; int(-1) ["ssl_verify_result"] =&gt; int(0) ["redirect_count"] =&gt; int(0) ["total_time"] =&gt; float(0.074915) ["namelookup_time"] =&gt; float(0.013638) ["connect_time"] =&gt; float(0.02722) ["pretransfer_time"] =&gt; float(0.056298) ["size_upload"] =&gt; float(6863) ["size_download"] =&gt; float(0) ["speed_download"] =&gt; float(0) ["speed_upload"] =&gt; float(92743) ["download_content_length"] =&gt; float(0) ["upload_content_length"] =&gt; float(6863) ["starttransfer_time"] =&gt; float(0.0563) ["redirect_time"] =&gt; float(0) ["redirect_url"] =&gt; string(0) "" ["primary_ip"] =&gt; string(12) "47.108.5.200" ["certinfo"] =&gt; array(0) { } ["primary_port"] =&gt; int(443) ["local_ip"] =&gt; string(13) "192.168.0.170" ["local_port"] =&gt; int(42156) ["http_version"] =&gt; int(2) ["protocol"] =&gt; int(2) ["ssl_verifyresult"] =&gt; int(0) ["scheme"] =&gt; string(5) "HTTPS" ["appconnect_time_us"] =&gt; int(56254) ["connect_time_us"] =&gt; int(27220) ["namelookup_time_us"] =&gt; int(13638) ["pretransfer_time_us"] =&gt; int(56298) ["redirect_time_us"] =&gt; int(0) ["starttransfer_time_us"] =&gt; int(56300) ["total_time_us"] =&gt; int(74915) ["method"] =&gt; string(3) "PUT" } ["oss-request-url"] =&gt; string(78) "https://edk24-com.oss-cn-chengdu.aliyuncs.com/d4f59b691015f8a6f6b40dafef913874" ["oss-redirects"] =&gt; int(0) ["oss-stringtosign"] =&gt; string(103) "PUT application/octet-stream Sat, 12 Sep 2020 06:25:06 GMT /edk24-com/d4f59b691015f8a6f6b40dafef913874" ["oss-requestheaders"] =&gt; array(5) { ["Accept-Encoding"] =&gt; string(0) "" ["Content-Type"] =&gt; string(24) "application/octet-stream" ["Date"] =&gt; string(29) "Sat, 12 Sep 2020 06:25:06 GMT" ["Host"] =&gt; string(37) "edk24-com.oss-cn-chengdu.aliyuncs.com" ["Authorization"] =&gt; string(49) "OSS LTAIZJxVcXCt11wZ:vE/rK4QuOgJUXIZhAYepbw9UkY4=" } ["body"] =&gt; string(0) "" } </pre> ``` ## 签名私有文件 把oss公开读是非常危险的, 一不小心你的流量就用光了, 哈哈哈 私有访问方式, 签名文件, 设定签名有效期内可访问 ```php ```