PHP code example of gitfei1231 / webman-storage

1. Go to this page and download the library: Download gitfei1231/webman-storage 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/ */

    

gitfei1231 / webman-storage example snippets


composer 

Tinywan\Storage\Storage::config(); // 初始化。 默认为本地存储:local,阿里云:oss,腾讯云:cos,七牛:qiniu,亚马逊aws:aws
$res = Tinywan\Storage\Storage::uploadFile();
var_dump(json_encode($res));

'local' => [
    'adapter' => \Tinywan\Storage\Adapter\LocalAdapter::class,
    'root' => public_path() . '/storage',
],

composer 

composer 

composer 

composer 

// 在 config/plugin/tinywan/storage/pp.php 中新增如下配置
'aws' => [
    'adapter' => \Tinywan\Storage\Adapter\AwsAdapter::class,
    'root' => 'storage' . DIRECTORY_SEPARATOR,
    'accessKeyId' => 'your-aws-access-key',
    'secretAccessKey' => 'your-aws-secret-key',
    'bucket' => 'your-bucket-name',
    'region' => 'us-east-1', // 选择你所使用的 AWS 区域
    'dirname' => function () {
        return date('Ymd');
    },
    'domain' => 'https://your-bucket.s3.amazonaws.com', // S3 Bucket 的访问 URL
    'endpoint' => '', // 可选,若有自定义 endpoint 可在此处配置
    'algo' => 'sha1', // 文件命名算法
],

public function upload(Request $request)
{
    Storage::config(Storage::MODE_OSS, false); // 第一个参数为存储方式。第二个参数为是否本地文件(默认是)
    $base64 = $request->post('base64');
    $r = Storage::uploadBase64($base64,'png');
    var_dump($r);
}

Storage::config(Storage::MODE_OSS,false);
$localFile = runtime_path() . DIRECTORY_SEPARATOR . 'storage/webman.png';
$res = Storage::uploadServerFile($localFile);
regexp
vendor/bin/phpstan analyse src

vendor/bin/php-cs-fixer fix src