PHPackages                             wester/chunk-upload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. wester/chunk-upload

ActiveLibrary[File &amp; Storage](/categories/file-storage)

wester/chunk-upload
===================

Handle chunked uploads with local and ftp drivers simply in PHP with advanced validation features and localization.

v2.6.3(1y ago)1711.5k↑106.7%6[1 issues](https://github.com/hossein-zare/wester-chunk-upload/issues)MITPHPPHP ^8.0

Since Sep 7Pushed 1y ago2 watchersCompare

[ Source](https://github.com/hossein-zare/wester-chunk-upload)[ Packagist](https://packagist.org/packages/wester/chunk-upload)[ RSS](/packages/wester-chunk-upload/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)DependenciesVersions (13)Used By (0)

Wester Chunk Upload Library For PHP
===================================

[](#wester-chunk-upload-library-for-php)

Wester chunk upload is a php library to handle chunked uploads which supports local and ftp file upload out of the box.
You'll feel safe with the built-in file validator.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Drivers](#drivers)
    - [Implement The Driver](#implement-the-driver)
- [Methods](#methods)
- [Properties](#properties)
- [Validation Rules](#validation-rules)
- [Language](#language)
- [Flags](#flags)
- [HTTP Response Status Codes](#http-response-status-codes)
- [Client Side](#client-side)
    - [Headers](#headers)
    - [Examples](#examples)
        - [Javascript](#javascript)
        - [Contribution](#contribution)
- [Support Us](#support-us)

Installation
------------

[](#installation)

```
composer require wester/chunk-upload
```

Basic Usage
-----------

[](#basic-usage)

Here's an example of the package.

```
// You don't need this line in laravel or some other frameworks.
require("./vendor/autoload.php");

use Wester\ChunkUpload\Chunk;
use Wester\ChunkUpload\Validation\Exceptions\ValidationException;

try {
    $chunk = new Chunk([
        'name' => 'video', // same as    $_FILES['video']
        'chunk_size' => 4000, // must be equal to the value specified on the client side

        // Driver
        'driver' => 'local', // [local, ftp]

        // Local driver details
        'local_driver' => [
            'path' => __DIR__ . '/uploads/', // where to upload the final file
            'tmp_path' => __DIR__ . '/uploads/temp/', // where to store the temp chunks
        ],

        // FTP driver details
        'ftp_driver' => [
            'server' => '',
            'username' => '',
            'password' => '',

            'path' =>  '/uploads/', // where to upload the final file
            'tmp_path' => '/uploads/temp/', // where to store the temp chunks
        ],

        // File details
        'file_name' => Chunk::RANDOM_FILE_NAME,
        'file_extension' => Chunk::ORIGINAL_FILE_EXTENSION,

        // File validation
        'validation' => ['extension:mp4,avi'],
    ]);

    $chunk->validate()->store();

    if ($chunk->isLast()) {

        // done
        $chunk->getFilePath();

    } else {
        $chunk->response()->json([
            'progress' => $chunk->getProgress()
        ]);
    }

} catch (ValidationException $e) {
    $e->response(422)->json([
        'message' => $e->getMessage(),
        'data' => $e->getErrors(),
    ]);
} catch (\Exception $e) {
    $e->response(400)->abort();
}
```

Drivers
-------

[](#drivers)

This package supports `ftp` file upload out of the box.
`local` and `ftp` or custom drivers can be used.

```
'driver' => 'ftp',
```

- ### Implement The Driver

    [](#implement-the-driver)

    Your custom driver should implement the `\Wester\ChunkUpload\Drivers\Contracts\DriverInterface`.

    ```
    'driver' => \My\Custom\Drivers\DriverName::class,
    'custom_driver' => [
        'path' =>  '/uploads/',
        'tmp_path' => '/uploads/temp/',
    ],
    ```

    ```
