szwtdl/storage

laravel-storage 阿里云oss,腾讯云cos,对象存储包

v0.0.1 2022-09-29 15:31 UTC

This package is auto-updated.

Last update: 2024-04-29 04:54:07 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads

安装

composer require szwtdl/storage

laravel安装

php artisan vendor:publish --provider="Szwtdl/Storage\ServiceProvider"

.env 配置文件

STORAGE_TYPE=tencent or aliyun
STORAGE_SECRET_ID=
STORAGE_SECRET_KEY=
STORAGE_REGION=ap-guangzhou
STORAGE_BUCKET=test-100000
STORAGE_DOMAIN=

laravel 使用教程

$object = "test/example.txt";
$content = "Hello OSS";
# 上传
app('upload')->upload($object,$content); 

#下载
app('upload')->download($object, './test.txt');

# 删除
app('upload')->delete($object);

初始化

require_once __DIR__ . '/vendor/autoload.php';
$options = [
    'storage_type' => 'aliyun',
    'storage_secret_id' => '',
    'storage_secret_key' => '',
    'storage_region' => '',
    'storage_bucket' => 'test',
    'storage_domain' => 'https://szwtdl.oss-cn-hangzhou.aliyuncs.com',
];
$upload = new \Szwtdl\Storage\Upload($options);

上传

$object = "test/example.txt";
$content = "Hello OSS";
try {
    $result = $upload->storage->upload($object, $content);
    dd($result);
} catch (Exception $e) {
    dd($e->getMessage());
}

下载

$object = "test/example.txt";
$path = './test/demo.txt'
try {
    $upload->storage->download($object, $path);
} catch (Exception $e) {
    dd($e->getMessage());
}

删除

$object = "test/example.txt";
try {
    $upload->storage->delete($object);
} catch (Exception $e) {
    dd($e->getMessage());
}