PHP code example of haosheng0211 / filament-media-browser
1. Go to this page and download the library: Download haosheng0211/filament-media-browser 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/ */
haosheng0211 / filament-media-browser example snippets
// config/filament-media-browser.php
return [
// Laravel filesystem disk
'disk' => 'public',
// Root directory for browsing
'directory' => 'media',
// Whitelist of disks the browser may operate on. null = only 'disk' above.
// Prevents authenticated users from pivoting to a private disk (e.g. 'local', 's3').
'allowed_disks' => null,
// Auth guard used to gate the browser. null = Filament's configured guard.
'guard' => null,
// Optional Gate ability that must pass to use the browser (null = disabled).
'authorization' => null,
// Allowed upload MIME types. NOTE: SVG is intentionally excluded from the
// 'image/*' shorthand (stored-XSS risk); opt in with 'image/svg+xml'.
'accepted_file_types' => ['image/*', 'video/*', 'audio/*'],
// Executable/script extensions always rejected on upload (polyglot protection).
'blocked_extensions' => ['php', 'phtml', 'phar', 'htaccess', 'html', 'js', /* ... */],
// Max upload size in KB
'max_file_size' => 10240,
// Output format: true = Storage::url(), false = relative path
'store_as_url' => true,
];
use MrJin\FilamentMediaBrowser\Forms\Components\MediaPicker;
// Basic usage — single image picker with preview
MediaPicker::make('featured_image');
// Multiple images (gallery)
MediaPicker::make('gallery')
->multiple()
->maxItems(10)
->reorderable(); // drag-to-reorder, enabled by default
// File picker (no image preview, shows path instead)
MediaPicker::make('attachment')
->mediaType('file');
// Custom disk and directory
MediaPicker::make('hero_image')
->mediaDisk('s3')
->mediaDirectory('uploads/heroes');
// Store relative path instead of URL
MediaPicker::make('document')
->storePath();
// Custom grid columns (default: 5, fewer = larger cards)
MediaPicker::make('hero')
->gridColumns(3);
use MrJin\FilamentFormsTinymce\TinyMceEditor;
TinyMceEditor::make('content');
// With custom disk/directory per field
TinyMceEditor::make('content')
->mediaDisk('s3')
->mediaDirectory('uploads/posts');
// Disable the file browser
TinyMceEditor::make('content')
->fileBrowser(false);
// From Livewire — single file
$this->dispatch('open-media-browser', statePath: 'data.image', mediaType: 'image');
// Multiple files with custom disk/directory
$this->dispatch('open-media-browser',
statePath: 'data.files',
mediaType: 'file',
multiple: true,
disk: 's3',
directory: 'uploads',
);
// Store relative path instead of URL
$this->dispatch('open-media-browser',
statePath: 'data.document',
mediaType: 'file',
storeAsUrl: false,
);
// Livewire
#[On('media-selected')]
public function onMediaSelected(
string $statePath,
string $url,
string $alt,
string $title,
string $filename,
string $extension,
int $size,
string $mime,
): void {
// Use the selected media URL and metadata
}