gelatocloud/flow-php-server 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gelatocloud/flow-php-server

最新稳定版本:v0.2.1

Composer 安装命令:

composer require gelatocloud/flow-php-server

包简介

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

README 文档

README

PHP library for handling chunk uploads. Library contains helper methods for:

  • Testing if uploaded file chunk exists.
  • Validating file chunk
  • Creating separate chunks folder
  • Validating uploaded chunks
  • Merging all chunks to a single file

This library is compatible with HTML5 file upload library: https://github.com/flowjs/flow.js

Basic Usage

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.
}

Make sure that ./chunks_temp_folder path exists. All chunks will be save in this temporary folder.

If you are stuck with this example, please read this issue: How to use the flow-php-server

Advanced Usage

$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
}

Delete unfinished files

For this you should setup cron, which would check each chunk upload time. If chunk is uploaded long time ago, then chunk should be deleted.

Helper method for checking this:

\Flow\Uploader::pruneChunks('./chunks_folder');

Cron task can be avoided by using random function execution.

if (1 == mt_rand(1, 100)) {
    \Flow\Uploader::pruneChunks('./chunks_folder');
}

Contribution

Your participation in development is very welcome!

To ensure consistency throughout the source code, keep these rules in mind as you are working:

  • All features or bug fixes must be tested by one or more specs.
  • Your code should follow PSR-2 coding style guide

统计信息

  • 总下载量: 2.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 41
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-05