Download the PHP package ragulara93/tus-php without Composer

On this page you can find all versions of the php package ragulara93/tus-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package tus-php



TusPHP

PHP Version Build Status Code Coverage Scrutinizer Code Quality Downloads Software License

Resumable file upload in PHP using tus resumable upload protocol v1.0.0

TusPHP Demo

Medium Article ⚡ Laravel & Lumen Integration ⚡ Symfony Integration ⚡ CakePHP Integration ⚡ WordPress Integration

tus is a HTTP based protocol for resumable file uploads. Resumable means you can carry on where you left off without re-uploading whole data again in case of any interruptions. An interruption may happen willingly if the user wants to pause, or by accident in case of a network issue or server outage.

Table of Contents

Installation

Pull the package via composer.

Usage

Basic Tus Architecture
Basic Tus Architecture

Server

This is how a simple server looks like.

You need to rewrite your server to respond to a specific endpoint. For example:

Nginx

A new config option fastcgi_request_buffering is available since nginx 1.7.11. When buffering is enabled, the entire request body is read from the client before sending the request to a FastCGI server. Disabling this option might help with timeouts during the upload. Furthermore, it helps if you’re running out of disc space on the tmp partition of your system.

If you do not turn off fastcgi_request_buffering and you use fastcgi, you will not be able to resume uploads because nginx will not give the request back to PHP until the entire file is uploaded.

A sample nginx configuration can be found here.

Apache

Default max upload size is 0 which means there is no restriction. You can set max upload size as described below.

Default redis and file configuration for server and client can be found inside config/server.php and config/client.php respectively. To override default config you can simply copy the file to your preferred location and update the parameters. You then need to set the config before doing anything else.

Alternately, you can set REDIS_HOST, REDIS_PORT and REDIS_DB env in your server to override redis settings for both server and client.

Client

The client can be used for creating, resuming and/or deleting uploads.

To check if the file was partially uploaded before, you can use getOffset method. It returns false if the upload isn't there or invalid, returns total bytes uploaded otherwise.

Delete partial upload from the cache.

By default, the client uses /files as an API path. You can change it with setApiPath method.

By default, the server will use sha256 algorithm to verify the integrity of the upload. If you want to use a different hash algorithm, you can do so by using setChecksumAlgorithm method. To get the list of supported hash algorithms, you can send OPTIONS request to the server.

Third Party Client Libraries

Uppy

Uppy is a sleek, modular file uploader plugin developed by same folks behind tus protocol. You can use uppy to seamlessly integrate official tus-js-client with tus-php server. Check out more details in uppy docs.

Tus-JS-Client

Tus-php server is compatible with the official tus-js-client Javascript library.

Cloud Providers

Many cloud providers implement PHP streamWrapper interface that enables us to store and retrieve data from these providers using built-in PHP functions. Since tus-php relies on PHP's built-in filesystem functions, we can easily use it to upload files to the providers like Amazon S3 if their API supports writing in append binary mode. An example implementation to upload files directly to S3 bucket is as follows:

Extension Support

Expiration

The Server is capable of removing expired but unfinished uploads. You can use the following command manually or in a cron job to remove them. Note that this command checks your cache storage to find expired uploads. So, make sure to run it before the cache is expired, else it will not find all files that needs to be cleared.

You can use--config option to override default redis or file configuration.

Concatenation

The Server is capable of concatenating multiple uploads into a single one enabling Clients to perform parallel uploads and to upload non-contiguous chunks.

Additionally, the server will verify checksum against the merged file to make sure that the file is not corrupt.

Events

Often times, you may want to perform some operation after the upload is complete or created. For example, you may want to crop images after upload or transcode a file and email it to your user. You can utilize tus events for these operations. Following events are dispatched by server during different point of execution.

Event Name Dispatched
tus-server.upload.created after the upload is created during POST request.
tus-server.upload.progress after a chunk is uploaded during PATCH request.
tus-server.upload.complete after the upload is complete and checksum verification is done.
tus-server.upload.merged after all partial uploads are merged during concatenation request.

Responding to an Event

To listen to an event, you can simply attach a listener to the event name. An TusEvent instance is created and passed to all of the listeners.

or, you can also bind some method of a custom class.

Middleware

You can manipulate request and response of a server using a middleware. Middleware can be used to run a piece of code before a server calls the actual handle method. You can use middleware to authenticate a request, handle CORS, whitelist/blacklist an IP etc.

Creating a Middleware

In order to create a middleware, you need to implement TusMiddleware interface. The handle method provides request and response object for you to manipulate.

Adding a Middleware

To add a middleware, get middleware object from server and simply pass middleware classes.

Or, you can also pass middleware class objects.

Skipping a Middleware

If you wish to skip or ignore any middleware, you can do so by using the skip method.

Setting up a dev environment and/or running examples locally

An ajax based example for this implementation can be found in examples/ folder. You can build and run it using docker as described below.

Docker

Make sure that docker and docker-compose are installed in your system. Then, run docker script from project root.

Now, the client can be accessed at http://0.0.0.0:8080 and the server can be accessed at http://0.0.0.0:8081. The default API endpoint is set to/files and uploaded files can be found inside uploads folder. All docker configs can be found in docker/ folder.

If you want a fresh start then you can use the following commands. It will delete and recreate all containers, images, and uploads folder.

We also have some utility scripts that will ease your local development experience. See Makefile for a list of all available commands. If you are not using make, then you can use shell scripts available here.

Contributing

  1. Install PHPUnit and composer if you haven't already.
  2. Install dependencies

  3. Run tests with phpunit

  4. Validate changes against PSR2 Coding Standards

You can use xdebug enable and xdebug disable to enable and disable Xdebug inside the container.

Questions about this project?

Please feel free to report any bug found. Pull requests, issues, and project recommendations are more than welcome!

Supporters


All versions of tus-php with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2.5 || ^8.0
ext-json Version *
guzzlehttp/guzzle Version ^6.3 || ^7.0
nesbot/carbon Version ^1.26.3 || ^2.0
predis/predis Version ^1.1
ramsey/uuid Version ^3.7 || ^4.0
symfony/console Version ^4.4 || ^5.0
symfony/event-dispatcher Version ^4.4 || ^5.0
symfony/http-foundation Version ^4.4 || ^5.0.7
symfony/mime Version ^4.4 || ^5.0.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ragulara93/tus-php contains the following files

Loading the files please wait ....