国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

大文件分片上傳

1.0.0 版本
2022-08-15 版本更新時(shí)間
831 安裝
4 star

簡(jiǎn)介

webman大文件分片上傳插件

安裝

composer require mongdch/webman-uploadslice

使用

配置文件


return [
    // 啟用插件
    'enable' => true,
    // 允許上傳的文件后綴
    'exts'      => [],
    // 分片文件大小限制
    'sliceSize' => 0,
    // 保存根路徑
    'rootPath'  => public_path() . DIRECTORY_SEPARATOR . 'upload',
    // 臨時(shí)文件存儲(chǔ)路徑,基于rootPath
    'tmpPath'   => 'tmp'
];

演示代碼


/**
 * 演示使用的上傳接口DEMO
 */

use Webman\Route;
use support\Request;
use mon\util\Validate;
use mon\util\exception\UploadException;
use Mongdch\WebmanUploadslice\UploadSlice;

// 上傳頁面
Route::any('/', function (Request $request) {
    return view('upload');
});

// 上傳接口
Route::post('/upload', function (Request $request) {
    $data = $request->post();
    // 驗(yàn)證數(shù)據(jù)
    $validate = new Validate();
    $check = $validate->data($data)->rule([
        'action'        => ['in:slice,merge'],
        'filename'      => ['required', 'str'],
        'chunk'         => ['int', 'min:0'],
        'chunkLength'   => ['required', 'int', 'min:0'],
        'uuid'          => ['required', 'str']
    ])->message([
        'action'        => 'action faild',
        'filename'      => 'filename faild',
        'chunk'         => 'chunk faild',
        'chunkLength'   => 'chunkLength faild',
        'uuid'          => 'uuid faild'
    ])->check();
    if (!$check) {
        return json(['code' => 0, 'msg' => $validate->getError()]);
    }
    // 驗(yàn)證上傳分片必須的參數(shù)
    if ($request->post('action') == 'slice' && is_null($request->post('chunk'))) {
        return json(['code' => 0, 'msg' => 'chunk required']);
    }
    if ($request->post('action') == 'slice' && empty($request->file())) {
        return json(['code' => 0, 'msg' => 'upload faild']);
    }

    // 上傳
    $sdk = new UploadSlice();
    $file = $request->file('file');
    try {
        if ($data['action'] == 'slice') {
            // 保存分片
            $saveInfo = $sdk->upload($data['uuid'], $file, $data['chunk']);
            return json(['code' => 1, 'msg' => 'ok', 'data' => $saveInfo]);
        }
        // 合并
        $mergeInfo = $sdk->merge($data['uuid'], $data['chunkLength'], $data['filename']);
        // $mergeInfo = $sdk->merge($data['uuid'], $data['chunkLength'], $data['filename'], 'dirname');
        return json(['code' => 1, 'msg' => 'ok', 'data' => $mergeInfo]);
    } catch (UploadException $e) {
        return json(['code' => 0, 'msg' => $e->getMessage()]);
    }

    return json($sdk->getConfig());
});

可參考example目錄中upload.html、route.php中前端及接口代碼,結(jié)合實(shí)際業(yè)務(wù)修改使用。

效果圖(可選)

贊助商