PHP code example of kkosmider / filament-dropzone

1. Go to this page and download the library: Download kkosmider/filament-dropzone library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kkosmider / filament-dropzone example snippets


use Kkosmider\FilamentDropzone\Forms\Components\Dropzone;

Dropzone::make('upload')
    ->uploadEndpointUrl('/api/upload-document')
    ->autoProcessQueue()
    ->allowMultiple()
    ->parallelUploads(4)
    ->clearOnFinish()
    ->directory('documents')
    ->acceptedFiles('application/pdf,.docx,.doc,application/vnd.openxmlformats-officedocument.wordprocessingml.document'),

Dropzone::make('upload')
    ->acceptedFiles('video/*')
    ->uploadEndpointUrl('/api/upload-video')
    ->chunking()
    ->maxFilesize(30000)  // 30GB
    ->chunkSize(40000000) // 40MB
    ->retryChunks()
    ->directory('videos')
    ->parallelChunkUploads()
    ->

$request->validate([
    'file' => 'ata with each chunk. Check dropzone.js documentation for more info.
$chunkIndex = (int) $request->input('dzchunkindex');
$chunksTotal = (int) $request->input('dztotalchunkcount');

$fileName = $request->file('file')->getClientOriginalName();

$chunkName = $fileName . '.part' . $chunkIndex;

if ($chunksTotal === 0) {
    $this->putToStorage($request->file('file'), $fileName);
} else {
    $this->putToStorage($request->file('file'), '/chunks/' . $chunkName);
}

// If all chunks have been uploaded, merge them into one file and delete the chunks
if ($chunkIndex === $chunksTotal - 1) {
    $filePath = $this->directory . DIRECTORY_SEPARATOR . $fileName;

    for ($i = 0; $i < $chunksTotal; $i++) {
        $chunkPath = $this->directory . '/chunks/' . $fileName . '.part' . $i;

        File::append($this->storage->path($filePath), File::get($this->storage->path($chunkPath)));
                
        $this->storage->delete($chunkPath);
    }
}

// Return response 200 so Dropzone knows the file was uploaded successfully        
return response()->json([
   'chunk' => $chunkName,
]);