code-lts/resumable.php

PHP package for Resumable.js

dev-main 2024-05-31 21:50 UTC

This package is auto-updated.

Last update: 2024-10-31 00:17:41 UTC


README

To use this project we recommend you to use point cloud technology's fork that is a maintained version of the original resumable.js library.

Installation

To install, use composer:

composer require code-lts/resumable.php

How to use

upload.php

<?php
include __DIR__ . '/vendor/autoload.php';

use ResumableJs\Resumable;

// Any library that implements Psr\Http\Message\{ServerRequestInterface, ResponseInterface};
// See https://github.com/Nyholm/psr7 as a tested example

$resumable = new Resumable($request, $response);
$resumable->tempFolder = 'tmps';
$resumable->uploadFolder = 'uploads';
$resumable->process();

More

Setting custom filename(s)

$originalName = $resumable->getOriginalFilename(); // will give you the original end-user file-name

$mySafeName = Security::sanitizeFileName($request->query('resumableFilename'));
$resumable->setFilename($mySafeName);// Override the safe filename

// process upload as normal
$resumable->process();

// you can also get file information after the upload is complete
if (true === $resumable->isUploadComplete()) { // true when the final file has been uploaded and chunks reunited.
    $filename = $resumable->getFilename();
}

Removed features

  • $resumable->getOriginalFilename() does not have a parameter to return the name without the extension
  • $resumable->getExtension() implement the logic yourself
  • preProcess() no longer exists, it was not very useful
  • the default value of uploadFolder was test/files/uploads and is now uploads
  • Does not calculate the number of chunks, it uses the param resumableTotalChunks

Testing

$ ./vendor/bin/phpunit