PHP code example of netipar / laravel-chunky
1. Go to this page and download the library: Download netipar/laravel-chunky 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/ */
netipar / laravel-chunky example snippets
use NETipar\Chunky\Facades\Chunky;
Chunky::simple('avatars', 'avatars', ['max_size' => 10 * 1024 * 1024, 'mimes' => ['image/jpeg', 'image/png']]);
use NETipar\Chunky\Profiles\CompletedUpload;
use NETipar\Chunky\Profiles\UploadContext;
use NETipar\Chunky\Profiles\UploadProfile;
class AvatarProfile extends UploadProfile
{
public function rules(): array
{
return ['file_size' => ['max:10485760'], 'mime_type' => ['in:image/jpeg,image/png']];
}
public function directory(UploadContext $context): string
{
return "avatars/{$context->userId()}";
}
public function authorize(UploadContext $context): bool
{
return $context->user !== null;
}
public function completed(CompletedUpload $upload): array
{
$media = Media::create(['disk' => $upload->disk, 'path' => $upload->path, 'user_id' => $upload->userId]);
return ['media_id' => $media->id]; // becomes the response `payload`
}
}
'profiles' => ['avatar' => \App\Chunky\Profiles\AvatarProfile::class],
class VideoProfile extends UploadProfile
{
public function transport(): string
{
return 'direct_s3';
}
// directory(), completed(), … as usual
}
bash
composer chunky:install # publishes config + migrations
php artisan migrate
bash
php artisan make:chunky-profile AvatarProfile
initiate ──▶ upload chunks (concurrent, retried) ──▶ assemble ──▶ completed
POST /upload POST /upload/{id}/chunks (sync or queued)