unisharp/laravel-filemanager
UniSharp Laravel Filemanager adds a responsive web file manager to Laravel for uploading, organizing, and selecting files/images. Includes routes, views, configuration, events, and easy integration with editors and custom apps.
Installation:
composer require unisharp/laravel-filemanager
php artisan vendor:publish --tag=lfm_config
php artisan vendor:publish --tag=lfm_view
php artisan vendor:publish --tag=lfm_lang
php artisan migrate
Run migrations to create necessary tables for file tracking.
Basic Route Configuration (in routes/web.php):
Route::group(['prefix' => 'lfm', 'middleware' => ['web', 'auth']], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
First Use Case: CKEditor Integration Add this to your CKEditor initialization:
CKEDITOR.replace('editor', {
filebrowserImageBrowseUrl: '/lfm?type=Images',
filebrowserBrowseUrl: '/lfm?type=Files'
});
filebrowserImageBrowseUrl and filebrowserBrowseUrl with ?type=Images or ?type=Files.file_picker_callback or use file_browser_callback with custom routes.filemanager plugin with the same route pattern.Create a button linking to the filemanager:
<a href="/lfm?type=Files" class="btn btn-primary">Upload Files</a>
Or use the iframe mode:
<iframe src="/lfm?type=Images" width="100%" height="600px"></iframe>
/storage/app/public/photos/{user_id}/).shared_folder_name in lfm.php (default: shares). All users can access files here.Leverage Laravel’s filesystem (e.g., S3, FTP) by setting the disk config in lfm.php:
'disk' => 's3',
Extend folder_categories in lfm.php for specialized folders (e.g., documents, videos):
'folder_categories' => [
'documents' => [
'folder_name' => 'docs',
'valid_mime' => ['application/pdf', 'application/msword'],
],
],
Listen to filemanager events (e.g., fileUploaded, fileDeleted) in EventServiceProvider:
protected $listen = [
\UniSharp\LaravelFilemanager\Events\FileUploaded::class => [
'App\Listeners\LogUploadedFile',
],
];
Authentication Middleware:
auth middleware (e.g., Route::group(['middleware' => ['auth']], ...)).File Permissions:
storage/app/public is writable:
chmod -R 775 storage/app/public
chown -R www-data:www-data storage/app/public # Adjust user/group as needed
Thumbnail Generation:
raster_mimetypes in lfm.php or disable with should_create_thumbnails: false.Route Conflicts:
use_package_routes in lfm.php and manually define routes.Large File Uploads:
post_max_size or upload_max_filesize limits in php.ini block uploads.lfm.php (note: caveats apply):
'php_ini_overrides' => [
'memory_limit' => '512M',
],
php artisan lfm:clear-cache to reset cached views/configs.dd() in event listeners to debug file operations:
public function handle(FileUploaded $event) {
dd($event->file); // Inspect uploaded file data
}
Custom Handlers:
ConfigHandler for dynamic folder naming:
php artisan publish --tag=lfm_handler
userField() to use custom user identifiers (e.g., email):
public function userField() {
return auth()->user()->email;
}
Custom Validation:
FileValidator by publishing the service provider:
php artisan publish --tag=lfm_provider
validate() method to enforce custom rules (e.g., file naming conventions).API Integration:
Lfm facade to trigger actions programmatically:
use UniSharp\LaravelFilemanager\Facades\Lfm;
$files = Lfm::getFiles('Images', ['perPage' => 100]);
Localization:
php artisan publish --tag=lfm_lang
en to resources/lang/vendor/laravel-filemanager/{locale}.should_create_thumbnails: false if not needed.paginator.perPage to limit API response sizes (default: 30).valid_mime to prevent malicious uploads.should_validate_size: true and set max_size to mitigate DoS risks.allow_private_folder: true to isolate user uploads and prevent unauthorized access.
```markdown
### **Pro Tips for Daily Workflows**
1. **Quick Testing**:
Use the standalone iframe (`/lfm?type=Images`) for ad-hoc uploads during development.
2. **Bulk Operations**:
Select multiple files in the grid/list view and use the bulk actions (delete, download) for efficiency.
3. **Image Editing**:
Leverage the built-in crop/resize tools for thumbnails or social media previews without external tools.
4. **Multi-Environment Configs**:
Override `lfm.php` per environment (e.g., `lfm-local.php`, `lfm-production.php`) for disk/storage differences.
5. **Backup Integration**:
Use the `fileDeleted` event to log deleted files for backup purposes:
```php
public function handle(FileDeleted $event) {
\Log::info('Deleted file: ' . $event->file->path);
}
php artisan vendor:publish --tag=lfm_migrations
Add columns like alt_text or metadata to files table for SEO or analytics.How can I help you explore Laravel packages today?