阿里云OSS文件上传

阿里云OSS文件上传


use OSS\OssClient;
use OSS\Core\OssException;

require 'aliyun-oss-php-sdk-2.2.2.phar';

$accessKeyId = "accessKeyId";
$accessKeySecret = "accessKeySecret";
$endpoint = "http://oss-cn-beijing-internal.aliyuncs.com";

try {
    $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
} catch (OssException $e) {
    print $e->getMessage();
    exit();
}

$bucket = 'bucket-name';
$object = "a.txt";
$filePath = __DIR__ . '/a.txt';

try{
    $ossClient->uploadFile($bucket, $object, $filePath);
} catch(OssException $e) {
    printf($e->getMessage() . "\n");
    exit();
}