文档 对象存储 OSSSDK示例PHP安装 对象存储 OSSSDK示例PHP上传文件简单上传 运行环境 PHP 5.3cURL 安装 composer require aliyuncs/oss-sdk-php 示例 ?phpuse OSS\OssClient;use OSS\Core\OssException;// 阿里云账号Ac
文档
- 对象存储 OSS>SDK示例>PHP>安装
- 对象存储 OSS>SDK示例>PHP>上传文件>简单上传
运行环境
PHP > 5.3 cURL安装
composer require aliyuncs/oss-sdk-php示例
<?php use OSS\OssClient; use OSS\Core\OssException; // 阿里云账号AccessKey $accessKeyId = "yourAccessKeyId"; $accessKeySecret = "yourAccessKeySecret"; $endpoint = "https://oss-cn-hangzhou.aliyuncs.com"; $bucket = "examplebucket"; $host = "https://examplebucket.oss-cn-hangzhou.aliyuncs.com" // 填写Object完整路径 $object = "exampledir/exampleobject.txt"; // 填写本地文件的完整路径 $filePath = "D:\\localpath\\examplefile.txt"; $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); $ossClient->uploadFile($bucket, $object, $filePath); $url = "${$host}/${$object}"; echo $url;