PHP code example of wzx2002 / upload

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

    

wzx2002 / upload example snippets


    // oss配置
    $oss_config = [
        'accessKeyId' => '',
        'accessKeySecret' => '',
        'endpoint' => ''
    ];
    
    // 七牛配置
    $qi_niu_config = [
        'accessKey' => '',
        'secretKey' => '',
        'domain' => ''
    ];
    
    // cos配置
    $cos_config = [
        'secretId' => '',
        'secretKey' => '',
        'region' => 'ap-shanghai'
    ];
    
    // 获取实例
    $instance = Upload::getInstance();
    /*
     * 设置驱动实现
     * OssUploadImpl oss
     * QiNiuUploadImpl 七牛
     * CosUploadImpl cos
     */
    $instance->setUploadInstance(OssUploadImpl::getInstance());
    // 配置
    $instance->setConfig($oss_config);
    // 普通/base64上传
    $instance->upload($file);
    // 普通/base64多图上传
    $instance->uploadMany($files);
    // 分块上传
    $instance->multiUploadFile($file);
    
    /*
     * 返回 errCode 为0则成功
     * [
     *      'data' => 'xxxxx',
     *      'msg' => '上传成功',
     *      'errCode' => 0
     * ]
     */
    

    $instance = Upload::getInstance();
    $instance->setUploadInstance(OssUploadImpl::getInstance());
    $instance->setBucket('wzx2002');
    $instance->setConfig([
        'accessKeyId' => '',
        'accessKeySecret' => '',
        'endpoint' => ''
    ]);

    $file = $request->file('file');
    
    // TODO 验证层 
    
    $res = $instance->upload($file);
    return response()->json($res);