定制 flowjs/flow-php-server 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

flowjs/flow-php-server

Composer 安装命令:

composer require flowjs/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

How to get started?

Setup Composer: https://getcomposer.org/doc/00-intro.md

Run this command in your project:

composer require flowjs/flow-php-server

This will create a vendor directory for you, which contains an autoload.php file.

Create a new php file named upload.php:

//Path to autoload.php from current location
require_once './vendor/autoload.php';

$config = new \Flow\Config();
$config->setTempDir('./chunks_temp_folder');
$request = new \Flow\Request();
$uploadFolder = './final_file_destination/'; // Folder where the file will be stored
$uploadFileName = uniqid()."_".$request->getFileName(); // The name the file will have on the server
$uploadPath = $uploadFolder.$uploadFileName;
if (\Flow\Basic::save($uploadPath, $config, $request)) {
  // file saved successfully and can be accessed at $uploadPath
} else {
  // This is not a final chunk or request is invalid, continue to upload.
}

Make sure that ./chunks_temp_folder path exists and is writable. All chunks will be saved in this 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 204 No Content");
        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

flowjs/flow-php-server 适用场景与选型建议

flowjs/flow-php-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.63M 次下载、GitHub Stars 达 245, 最近一次更新时间为 2013 年 10 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「flow」 「upload」 「file upload」 「resumable.js」 「resumable」 「html5 file upload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 flowjs/flow-php-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 flowjs/flow-php-server 我们能提供哪些服务?
定制开发 / 二次开发

基于 flowjs/flow-php-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.63M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 248
  • 点击次数: 31
  • 依赖项目数: 17
  • 推荐数: 0

GitHub 信息

  • Stars: 245
  • Watchers: 20
  • Forks: 41
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-10-04