Let's consider the implementation using the Laravel framework. We will need the following libraries:
- Resumable.js - a JavaScript library that provides multiple concurrent, stable, and resumable uploads via the HTML5 File API
- https://github.com/pionl/laravel-chunk-upload - a library for Laravel for uploading files in chunks
- jQuery
First, download the resumable.js file from the repository https://github.com/23/resumable.js/ and place it in our project /public/js/resumable.js/
Next, we need to install the library https://github.com/pionl/laravel-chunk-upload using composer
composer require pion/laravel-chunk-upload
No access to global composer?
Once all the libraries are installed, let's move on to creating the controller responsible for the upload.
First, add new routes to the file /routes/web.php
Route::get('/files-library', App\Http\Controllers\FilesLibraryController::class, 'filesLibrary')->name('files-library');
Route::post('files-library/upload', App\Http\Controllers\UploaderController::class, 'upload')->name('file-upload');
The path /files-library will be used for the file upload page, and files-library/upload is for the actual upload process.
In the folder /app/Http/Controllers, create a new controller FilesLibraryController.php
// /app/Http/Controllers/FilesLibraryController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FilesLibraryController extends Controller
{
public function filesLibrary(Request $request) {
return view('/files.library')
}
}
Next, let's create the file uploader controller UploaderController.php