A file library for Filament panels: folders, versions, previews, and files delivered and audited by your app.
Being built. Each section here is written as its feature lands. Fileble needs PHP 8.3, Laravel 12 or 13 and Filament 5.
Installing
composer require polycode/fileble
php artisan migrate
Add a private disk named fileble to config/filesystems.php, or point FILEBLE_DISK at one you
have. Fileble refuses a public disk, or a local one inside public/, because every file has to go
through your app.
Register the plugin on each panel that opens files:
use Polycode\Fileble\FileblePlugin;
$panel->plugin(FileblePlugin::make());
Publish the config with php artisan vendor:publish --tag=fileble-config when you want to change
it. Anything left out falls back to Fileble's own default.
The library page
The plugin adds a Files page to the panel, at files (paths.library). It has the folder tree
beside a table of the chosen folder's files, or every open folder's files under All files. People
can:
- make, rename and move folders, as deep as
limits.depthallows (no limit unless you set one), and delete a folder with everything inside it; - choose who sees a folder: everyone, only themselves (
features.private_folders), or the groups your host offers (features.audiences). Only the folder's creator can change this; - set a password on a folder (
features.passwords, off by default), which locks every folder inside it too. A locked folder shows a password box in place of its files, and nothing inside it until it's unlocked; - turn downloads off for a folder and everything inside it (
features.downloads_switch); - upload up to
limits.files_per_uploadfiles at once, and rename, move and delete files; - see a file's versions in its Edit, newest first, each with who uploaded it, when and its
checksum, upload a new version with a note on what changed, and restore an older one, which
adds a copy of it on top (
features.versions); - choose several files to move, delete or download as one zip at once (
features.bulk,features.zip_downloads); - tag files and filter by tag (
features.tags), and give a file a date it's due for review, with a filter for what's due (features.review_dates); - search by name and by the words inside PDFs, text files and an Office file's PDF copy
(
features.search_contents), filter by type, sort, page through at the sizes inlimits.page_sizes, and switch between a list and a grid; - see the files on records under On records, with the records each one is on, filtered by record type and by slot together. Only records the person can see are listed;
- press a file's name to preview it (
features.preview), and empty, restore from or delete from the bin (features.bin), for the people your host lets manage the library; - see how much the library holds, under the folders, for the people who manage it
(
features.storage_usage). Withlimits.storage_megabytesset, a new file that would take the library past it is refused; a copy of bytes it already holds takes no more room.
With features.bin on, a deleted file or folder goes to the bin; off, it's deleted for good, and its
stored bytes go too unless another file still uses them. See The bin.
Each change is checked again on the server, so a button someone can't see does nothing when it's called another way.
Where the page appears
Change the label, icon, group, sort or placement in navigation.library, or on the plugin:
FileblePlugin::make()
->navigationGroup('Records')
->navigation('library', label: 'Documents', placement: Placement::UserMenu);
Placement is Placement::Sidebar, UserMenu, SidebarAndUserMenu or Hidden. The plugin's
settings win over config.
The page's own words
A line under the title, and what the page says before there are any files, come from config or the plugin, which wins:
FileblePlugin::make()
->subheading('Documents the board keeps: policies, plans and reports.')
->emptyState('No resources yet', 'Make a folder, then upload files into it.');
The keys are library.subheading, library.empty.heading and library.empty.description. The
empty picture is the fileble::empty-state icon alias (below).
Icons
Every icon Fileble draws has a Filament icon alias, listed in Polycode\Fileble\Support\Icons.
Change one in a service provider's boot():
use Filament\Support\Facades\FilamentIcon;
FilamentIcon::register([
'fileble::folder' => 'heroicon-o-archive-box',
'fileble::folder.locked' => 'heroicon-o-shield-check',
]);
The folder tree uses folder, folder.locked, folder.private and folder.shared, and each
button has its own under actions.. A file shows its type as a coloured badge with its extension
on it, which has no icon.
Keeping a file
Every new file goes through Fileble::keep():
use Polycode\Fileble\Fileble;
$file = Fileble::keep($upload)->inFolder($folder)->by($user)->save();
$file = Fileble::keep($upload)->on($job, 'photos')->by($user)->save();
inFolder()puts it in a folder, andon($record, $slot)puts it on a record, in a slot of your choosing such asphotosorreceipts. A file can be in a folder and on records at once.named()sets the name people see. Otherwise it's the uploaded file's name without its extension.Fileble::keepContents($pdf, 'Minutes.pdf')keeps bytes your app made, from a string or a stream.once($key)keeps the file only the first time it's saved with that key, and returns that same file every time after. Use it when a job might run twice.
Fileble::newVersion($file, $upload, $user, $note) adds the next version, with an optional note on
what changed. A version with the same bytes as the current one isn't added, and the person is told
so.
Each file's bytes are stored once, under their checksum, so two identical uploads take the space of one. The stored path never includes a name, so renaming a file never moves anything on the disk.
A file Fileble won't keep throws Polycode\Fileble\Storing\Refused, with a sentence you can show
the person as it is.
Files on records
A record keeps its files in slots you name, such as photos or receipts. Add HasFiles to the
model:
use Polycode\Fileble\Models\Concerns\HasFiles;
class Job extends Model
{
use HasFiles;
}
$job->files('photos'); // in their order
$job->files(); // every slot
$job->attachFile($file, 'photos');
$job->detachFile($file, 'photos');
A file can be in a folder and on several records at once. Taken off its last record, a file with no
folder goes to the bin (features.bin), unless your DeleteGuard keeps it. Deleting the record
takes its files off it; a soft delete leaves them there.
Each record type with files needs an attachment source in sources (below). It decides who sees
the record's files and who can change them. A record type with no source stops with a message
naming it.
On the record's form
use Polycode\Fileble\Forms\AttachedFiles;
AttachedFiles::make('photos')->multiple()->fromLibrary();
AttachedFiles::make('cover');
The field's name is the slot. Uploads pass the checks while the form validates, so a refused file
stops the save with its reason beside the field. Everything is saved once the record is, including
on a new record's form. fromLibrary() adds Choose from the library, which offers files from the
folders open to the person (features.record_picker). Someone who can see the record but not
change it sees the files without being able to change them.
The Files tab
use Polycode\Fileble\RelationManagers\FilesRelationManager;
public static function getRelations(): array
{
return [FilesRelationManager::class];
}
A slot reads as its key in words (site_photos reads Site photos). To name one yourself, add it to
lang/vendor/fileble/en/slots.php: 'site_photos' => 'Photos from site'.
The tab lists every file on the record with its slot, and the folder it's also in when the person
can see that folder. It has Upload files, Choose from the library and Remove. Uploads go into the files slot. For a tab that shows one slot only, extend it and set
protected static ?string $slot = 'photos';. Turn the tab off with
features.record_attachments_tab.
The field and the tab are two views of the same files, so a file added on one shows on the other.
Previews
Each new file's previews are made once it's kept, on pdf.queue, or straight away when your app has
no queue:
- a picture gets a thumbnail for the grid and the upload box, which opens without being recorded in the access log;
- a PDF gets its page count and a thumbnail of its first page, through
pdf.reader.PopplerReaderusespdfinfoandpdftoppmwhen Poppler is installed; - an Office file gets a PDF copy through
pdf.converter, to preview in its place. Setpdf.convertertoGotenbergConverterandFILEBLE_GOTENBERG_URLto a Gotenberg server, or leave it atNoConversion.
Pressing a file's name shows a picture, video or sound file on the page. A PDF, or an Office file's
PDF copy, opens in a new tab in the browser's own reader, and anything else downloads. Thumbnails
need PHP's GD extension. Replace the reader or converter with your own by implementing
Contracts\ReadsPdfs or Contracts\ConvertsToPdf.
Checks before a file is kept
Every file passes the size limit (limits.max_kilobytes), then each class in checks, in order:
SniffedTypereads the type from the file's contents and keeps only what's inaccepted_types. SVG is never on the list, since an SVG can run script.PixelLimitrefuses a picture overlimits.pixels, read from its header before anything opens it.ClamdScansends the file to ClamAV's daemon whenclamd.socketis set. Withclamd.requiredon, nothing is kept while the scanner can't be reached.
Add your own by implementing Polycode\Fileble\Contracts\Check and listing it in checks, or
remove one you don't want.
After an upload, a summary lists each file with the checks it passed, then Kept, or the check
that refused it and why (features.upload_summary; off, each refusal is a notification). A check
appears only when it looked at the file: Pixels for a picture, Virus scan once the scanner has
answered. Your own check is named after its class (NoMacros reads No macros), or implement
Contracts\DescribesCheck to name it yourself.
Opening files
With delivery.secure on, as it is by default, a file's link is a route on your panel:
$file->url(); // opens in the browser when its type is in inline_types
$file->url('download');
Each request checks that the person is signed in to that panel and can reach the file. The file is
sent with Cache-Control: private, no-store, so the browser keeps no copy, and with byte ranges, so
a PDF reader can show the first page of a long file before the rest arrives. Anything not in
inline_types downloads.
With delivery.secure off, a link goes straight to the disk, signed for delivery.link_minutes.
Who can reach a file
A person can open a file when it's in a folder open to them, or on a record they can see.
- A folder is seen by everyone who uses the library, by its creator only, or by the groups it's shared with. A folder inside one somebody can't see is hidden from them too.
- A folder's password locks it and every folder inside it. Giving the password opens that branch for the rest of the session, and changing the password locks it again.
- Downloads can be turned off for a folder and everything inside it. A folder further in can turn them back on.
- A file on a record is reachable through an attachment source (below) that lets the person see that record.
The bin
People your host lets manage the library (canManage()) see the Bin in the folder tree. A folder
goes into the bin with everything inside it, and Restore brings it all back, leaving out anything
deleted on its own before. A folder whose own folder is in the bin comes back at the top level. A
file whose folder isn't there any more asks for a folder to go into, unless it's on a record.
Delete for good and Empty the bin keep anything your DeleteGuard refuses. Schedule the command
that deletes what's been in the bin longer than bin.days, and the one that trims the access log:
Schedule::command('fileble:empty-bin')->daily();
Schedule::command('fileble:prune-access-log')->daily();
Schedule::command('fileble:reviews-due')->daily();
fileble:reviews-due fires FileReviewDue for each file whose review date is today, for your app
to tell someone. fileble:read-text is a one-off: it queues the PDFs and text files kept before
search read inside them.
Each covers every tenant in the database. Under stancl/tenancy with a database for each tenant,
run them through tenants:run.
The access log
Each view and download is written to fileble_access_log and fires
Polycode\Fileble\Events\FileOpened, so your app can also write it to its own audit log. A PDF
read in several byte ranges counts as one open. Turn the table off with features.access_log; the
event still fires. Recording opens needs delivery.secure on, and the panel won't start with the
log on and secure delivery off.
The Access log page (file-access-log, paths.access_log) lists who opened which file, how, which
version and when, newest first, filtered by how, by person and by date. Only the people your host
lets manage the library reach it, and it lists only files they can reach themselves. A file's Edit
has Who opened it, which shows that file's opens. Turn the page off with
features.access_log_screen; its menu item is navigation.access_log.
Telling Fileble about your app
host names a class that extends Polycode\Fileble\Hosts\SingleApp. Override only what differs:
- Access (
Contracts\Access): who can use the library, change a folder or file, manage the library, unlock a folder, change who sees a folder, and download.audiencesOf()gives the groups a person is in, as keys such asboard:3, andaudiences()lists every group a folder can be shared with.seesEveryFolder()lets someone see every shared folder without being in its groups. By default everyone signed in can do everything, except that only a folder's creator changes who sees it. - The tenant (
Contracts\TenantKey): Filament's tenant inside a panel with tenancy, otherwise stancl/tenancy's when it's installed. Every row is kept under the tenant's key, and every file in the tenant's own folder on the disk, so one tenant never finds another's. - Files you must keep (
Contracts\DeleteGuard): return a sentence to refuse a delete. - A copy for each reader (
Contracts\PreparesDownloads): return the path of a copy made for the person downloading, such as one with their name on every page, or null to send the file as kept. - People's names (
Contracts\NamesPeople):namesOf()names who uploaded each version. By default it's Filament's name for each user on the panel's guard.
Record types go in sources, one Contracts\AttachmentSource class each:
visibleTo()is a query for the records this person can see. Their files open, and no others.canChange()says whether the person can add and remove files on one record.label()names the type under On records, andtitle()names each record there.
Fileble fires an event for each of these, in Polycode\Fileble\Events, so your app can write them
to its own audit log: FileKept, VersionAdded, FileOpened, FileAttached, FileDetached,
FileBinned, FileRestored, FileDeleted, FileReviewDue, FolderCreated, FolderChanged
(with what changed: renamed, moved, shared, password or downloads), FolderUnlocked,
FolderBinned, FolderRestored and FolderDeleted.
Moving files over from another library
Fileble::adopt() takes on a file already on a disk, where it is, without copying or checking it
again:
Fileble::adopt(disk: 's3-files', path: $old->path, name: $old->name)
->on($old->record, 'documents')
->by($old->uploaded_by)
->at($old->created_at)
->once('old-library:'.$old->id)
->save();
once() makes the command safe to run again after it stops part way.