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

文档

运行环境

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;

猜你喜欢

转载自blog.csdn.net/mouday/article/details/127429224