PHP code example of itinysun / laravel-cos
1. Go to this page and download the library: Download itinysun/laravel-cos library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
itinysun / laravel-cos example snippets
return [
'default' => [
'app_id' => env('COS_APP_ID'),
'secret_id' => env('COS_SECRET_ID'),
'secret_key' => env('COS_SECRET_KEY'),
'bucket' => env('COS_BUCKET'), // 不带数字 app_id 后缀
'region' => 'ap-beijing',
// 可选,如果 bucket 为私有访问请打开此项
'signed_url' => true,
// 可选,是否使用 https,默认 false
'use_https' => true,
// 可选,自定义域名
'domain' => '',
// 可选,使用 CDN 域名时指定生成的 URL host
'cdn' => '',
'prefix' => '', // 全局路径前缀
],
];
//直接使用cos客户端
$laravelCos = new Itinysun\LaravelCos\Lib\LaravelCos('default');
// 上传文件
$laravelCos->uploadFile('test.txt', 'local/test.txt');
//使用facade
use Itinysun\LaravelCos\Facades\LaravelCos;
LaravelCos::uploadFile('test.txt', 'local/test.txt');
//使用laravel的storage
//首先在config/filesystems.php 中添加一个 disk,config_name 是上面配置文件中的key
'cos_disk' => [
'driver' => 'cos',
'config_name' => 'cos_source',
],
//然后就可以使用laravel的storage了
bash
php artisan vendor:publish --tag="cos-config"