unisharp/laravel-filemanager
UniSharp Laravel Filemanager adds a responsive web-based file manager to Laravel apps. Browse, upload, organize and delete files and images, integrate with editors like TinyMCE/CKEditor, configure disks, permissions, and customization options.
composer require unisharp/laravel-filemanager
php artisan vendor:publish --tag=lfm_config
php artisan vendor:publish --tag=lfm_public
php artisan storage:link
routes/web.php):
Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'auth']], function () {
\UniSharp\LaravelFilemanager\Lfm::routes();
});
/laravel-filemanager/demo to test the UI.<script src="//cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
<script>
CKEDITOR.editorConfig = function(config) {
config.filebrowserBrowseUrl = '/laravel-filemanager?type=Files';
config.filebrowserImageBrowseUrl = '/laravel-filemanager?type=Images';
config.filebrowserUploadUrl = '/laravel-filemanager/upload';
config.filebrowserUploadMethod = 'form';
};
</script>
File Uploads:
valid_mime and max_size in config/lfm.php.tinymce.init({
selector: 'textarea',
plugins: 'image',
file_picker_callback: function(callback, value, meta) {
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/*');
input.onchange = function() {
var file = input.files[0];
var reader = new FileReader();
reader.onload = function() {
var id = 'blobid-' + (new Date()).getTime();
var blobCache = tinymce.activeEditor.editorUpload.blobCache;
var blobInfo = blobCache.create(id, file, reader.result);
callback(blobInfo.blobUri(), { title: file.name });
};
reader.readAsDataURL(file);
};
input.click();
}
});
Image Processing:
Intervention/Image for cropping/resizing via events (e.g., ImageWasUploaded).public function onImageWasUploaded(ImageWasUploaded $event) {
$path = $event->path();
$img = Image::make($path)->resize(300, 200)->save();
}
Multi-User Folders:
private_folder_name and shared_folder_name in config.Cloud Storage:
filesystems in config/filesystems.php (e.g., S3, FTP).lfm_disk in config/lfm.php to use a custom disk.<iframe src="/laravel-filemanager?type=Files" width="100%" height="500px"></iframe>
use_package_routes: false and defining custom routes.?locale=ar (supports 30+ locales).Permissions:
storage/app/public and subdirectories are writable (chmod -R 775 storage/).php artisan storage:link --force.Image Processing:
exif, fileinfo, or GD/Imagick extensions will break image features.php -m to check extensions.Multi-User Mode:
auth middleware; otherwise, users may access others' files.ConfigHandler requires publishing the handler:
php artisan vendor:publish --tag=lfm_handler
Caching:
php artisan route:clear
php artisan config:clear
storage/logs/laravel.log for upload errors.dd($event->path()) in listeners to inspect file paths.lfm_public assets for missing files.Custom Validation:
Override validateUpload in a published Handler:
public function validateUpload($request, $type) {
$rules = parent::validateUpload($request, $type);
$rules['file'][] = 'dimensions:max_width=2000,max_height=2000';
return $rules;
}
Custom Views:
Publish views and override templates (e.g., resources/views/vendor/lfm/).
API Extensions: Extend the API via middleware or service providers:
Lfm::addMiddleware('lfm', function ($request, $next) {
if ($request->user()->isAdmin()) {
return $next($request);
}
abort(403);
});
Cloud Storage Quirks:
public ACL is set for uploaded files.ftp_passive_mode: true in config/filesystems.php).File model to support soft deletes via deleted_at.public function onFileWasUploaded(FileWasUploaded $event) {
\App\Models\AuditLog::create([
'user_id' => auth()->id(),
'action' => 'file_uploaded',
'path' => $event->path(),
]);
}
How can I help you explore Laravel packages today?