overtrue/laravel-filesystem-cos

A Cos storage filesystem for Laravel.

2.0.0 2020-10-30 07:38 UTC

This package is auto-updated.

Last update: 2020-10-30 07:40:06 UTC


README

Tencent Cloud COS storage for Laravel based on overtrue/flysystem-cos.

Requirement

  • PHP >= 7.4

Installation

$ composer require "overtrue/laravel-filesystem-cos" -vvv

Configuration

  1. Add a new disk to your config/filesystems.php config:

🚨 当前为 v2 版本,v2 和 v1 在配置写法上有差异,升级请注意。

<?php

return [
   'disks' => [
       //...
       'cos' => [
           'driver' => 'cos',
           
           'app_id'     => env('COS_APP_ID'),
           'secret_id'  => env('COS_SECRET_ID'),
           'secret_key' => env('COS_SECRET_KEY'),
           'region'     => env('COS_REGION', 'ap-guangzhou'),
           
           'bucket'     => env('COS_BUCKET'), 
           'cdn'        => env('COS_CDN'),
           'signed_url' => false,
           
           'guzzle' => [
               'timeout' => env('COS_TIMEOUT', 60),
               'connect_timeout' => env('COS_CONNECT_TIMEOUT', 60),
           ],
       ],
       //...
    ]
];

🚨 请注意:example-1230000001.cos.ap-guangzhou.mycloud.com

其中:bucket: example, app_id: 1230000001, region: ap-guangzhou

Usage

$disk = Storage::disk('cos');

// create a file
$disk->put('avatars/filename.jpg', $fileContents);

// check if a file exists
$exists = $disk->has('file.jpg');

// get timestamp
$time = $disk->lastModified('file1.jpg');
$time = $disk->getTimestamp('file1.jpg');

// copy a file
$disk->copy('old/file1.jpg', 'new/file1.jpg');

// move a file
$disk->move('old/file1.jpg', 'new/file1.jpg');

// get file contents
$contents = $disk->read('folder/my_file.txt');

// fetch url content
$file = $disk->fetch('folder/save_as.txt', $fromUrl);

// get file url
$url = $disk->getUrl('folder/my_file.txt');

Full API documentation.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT