处理分块上传的PHP库。与flow.js的HTML5文件上传功能兼容。
v0.2.1
2013-11-14 09:22 UTC
Requires (Dev)
- league/phpunit-coverage-listener: ~1.1
- mikey179/vfsstream: v1.2.0
This package is not auto-updated.
Last update: 2024-09-24 17:21:59 UTC
README
处理分块上传的PHP库。库中包含以下辅助方法:
- 测试上传文件分块是否存在。
- 验证文件分块。
- 创建单独的分块文件夹。
- 验证上传的分块。
- 将所有分块合并为单个文件。
此库与HTML5文件上传库兼容:[https://github.com/flowjs/flow.js](https://github.com/flowjs/flow.js)
基本用法
if (\Flow\Basic::save('./final_file_destination', './chunks_temp_folder')) { // file saved successfully and can be accessed at './final_file_destination' } else { // This is not a final chunk or request is invalid, continue to upload. }
确保./chunks_temp_folder
路径存在。所有分块都将保存在此临时文件夹中。
如果您在这个示例中遇到困难,请阅读此问题:[如何使用flow-php-server](https://github.com/flowjs/flow-php-server/issues/3#issuecomment-46979467)
高级用法
$config = new \Flow\Config(); $config->setTempDir('./chunks_temp_folder'); $file = new \Flow\File($config); if ($_SERVER['REQUEST_METHOD'] === 'GET') { if ($file->checkChunk()) { header("HTTP/1.1 200 Ok"); } else { header("HTTP/1.1 404 Not Found"); return ; } } else { if ($file->validateChunk()) { $file->saveChunk(); } else { // error, invalid chunk upload request, retry header("HTTP/1.1 400 Bad Request"); return ; } } if ($file->validateFile() && $file->save('./final_file_name')) { // File upload was completed } else { // This is not a final chunk, continue to upload }
删除未完成的文件
为此,您应该设置cron,它会检查每个分块的上传时间。如果分块上传时间过长,则应该删除该分块。
用于检查的辅助方法
\Flow\Uploader::pruneChunks('./chunks_folder');
可以通过使用随机函数执行来避免cron任务。
if (1 == mt_rand(1, 100)) { \Flow\Uploader::pruneChunks('./chunks_folder'); }
贡献
非常欢迎您参与开发!
为确保源代码的一致性,在您工作时请记住以下规则:
- 所有功能或错误修复都必须通过一个或多个规格进行测试。
- 您的代码应遵循PSR-2编码风格指南