mehrdad-dadkhah/chunks-uploader

上传块文件。用于上传大文件

1.4.3 2018-01-29 10:47 UTC

This package is auto-updated.

Last update: 2024-09-22 18:21:00 UTC


README

Software License Packagist Version Packagist

用于上传文件块并将它们合并以上传大文件的上传器。

安装

composer require mehrdad-dadkhah/chunks-uploader

用法

use MehrdadDadkhah\Video\ChunksUploader;

$uploadHandeler = new ChunksUploader();
$uploadHandeler->setMainFileName('myFile.mp4') //main file name
            ->setFileTotalSize($_REQUEST['totalfilesize']) //size of main file (big file)
            ->setInputName('file') //your form input file name
            ->setChunksFolderPath('path-to-chunks-folder') //path to folder for upload chunks files
            ->setUniqueIdentifier('unique-id'); // set unique identifier for each upload (for example user id + time or ...) a unique indentifier per each upload

上传你的块

$uploadResult = $uploadHandeler->uploadChunk('name-of-chunk-or-chunk-number'); //should be a sortable name

并且当所有块上传完成后

$uploadResult = $uploadHandeler->setUploadDirectory('path-to-upload-directory') //main directry path to upload (combine chunks here)
			->finishUpload();

自定义文件名

如果想要设置输出文件名,请在调用 finishUpload() 函数之前使用 setUploadName() 函数

$uploadHandeler->setUploadName('my-name.mp4');

如果不设置名称,文件名将是 YYYY_m_d_hashname.mp4 的结构,并在最终结果中返回。

检查和生成输出目录

如果想要自动创建输出目录,请设置它

$uploadHandeler->checkAndGenerateOutputDirectory();

临时目录

如果想要在临时目录中生成文件,然后将其移动到主要上传目录,可以使用 setTempDirectory() 函数

$uploadHandeler->setTempDirectory('path-to-temp');

最大上传大小

ChunksUploader 计算上传文件的大小(块的总和)并与 upload_max_filesize ini 配置进行比较。如果想要在第一次请求时停止较大的文件以获得更好的用户体验,可以传递以字节为单位的总主文件大小

$uploadHandeler->setVideoTotalSize(213456);

并且可以通过以下方式覆盖 upload_max_filesize

$uploadHandeler->setMaxUploadSize(213456);

许可证

hls-video-generater 在 GPLv3 许可证下授权。GPLv3 许可证.