0
点赞
收藏
分享

微信扫一扫

PHP:将本地文件上传到阿里云OSS存储

文档

  • 对象存储 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;
举报

相关推荐

0 条评论