janfish/file-slice-upload

janfish file slice upload

dev-master 2021-05-08 17:19 UTC

This package is not auto-updated.

Last update: 2024-10-06 09:50:50 UTC


README

文件分片上传

文件分片,实现超大文件的在线上传

$chunkQuantity = $_POST['chunkQuantity'];
$currentChunkNo = $_POST['chunkNo'];
$fileName = $_FILES['file']['name'];
$tempPath = $_FILES['file']['tmp_name'];
$all = pathinfo($fileName);
$extension = $all['extension'];
$name = $all['filename'];
$dist = 'files/' . $name . '.' . $extension;

$file = new Janfish\Upload\File($chunkQuantity);
$file->setSessionKey($fileName);
if (!$file->append($currentChunkNo, $tempPath, $dist)) {
    die(json_encode([
        'status'=>'success',
        'data' => [
            'path' => $dist,
            'url' => '',
            'isFinished' => false,
        ],
    ]))
}
die(json_encode([
    'status'=>'success',
    'data' => [
        'path' => $dist,
        'url' => '',
        'isFinished' =>  $file->isFinished(),
    ],
]))

html Vue组件

基于elementUi

<slice-upload
    v-model="video"
    btn-text="上传视频"
    api="/resources/video"
    accept="application/x-msdownload;application/pdf"
    :show-progress="true"
    chunk-size="1"
    @on-progress="progressHandle"
    @on-error="errorHandle" />
  • 参数
  • 事件