2017 © Pedro Peláez
 

library flow-php-server

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

image

flowjs/flow-php-server

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

  • Tuesday, October 31, 2017
  • by AidasK
  • Repository
  • 19 Watchers
  • 168 Stars
  • 319,083 Installations
  • PHP
  • 15 Dependents
  • 0 Suggesters
  • 39 Forks
  • 14 Open issues
  • 9 Versions
  • 7 % Grown

The README.md

flow.js php server Build Status Coverage Status

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, (*1)

This library is compatible with HTML5 file upload library: https://github.com/flowjs/flow.js, (*2)

How to get started?

Setup Composer: https://getcomposer.org/doc/00-intro.md, (*3)

Run this command in your project:, (*4)

composer require flowjs/flow-php-server

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

Create a new php file named upload.php:, (*6)

//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., (*7)

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

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., (*9)

Helper method for checking this:, (*10)

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

Cron task can be avoided by using random function execution., (*11)

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

Contribution

Your participation in development is very welcome!, (*12)

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, (*13)

The Versions

31/10 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

22/04 2017

v1.0.3

1.0.3.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

01/10 2016

v1.0.2

1.0.2.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

13/07 2016

v1.0.1

1.0.1.0

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

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

01/02 2015

v1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

14/11 2013

v0.2.1

0.2.1.0

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

  Sources   Download

MIT

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

05/11 2013

v0.2.0

0.2.0.0

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

  Sources   Download

MIT

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

31/10 2013

v0.1.1

0.1.1.0

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

  Sources   Download

MIT

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js

04/10 2013

v0.1.0

0.1.0.0

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

  Sources   Download

MIT

The Development Requires

by Aidas Klimas

upload flow file upload chunks resumable.js resumable html5 file upload flow.js