Forms

Upload

A file field with a drop area, previews of the chosen files, progress while they upload through Livewire, limits on type, size and count, and a preview modal for images, videos, audio and PDFs. It comes in several layouts: a dropzone, a button, a list, a gallery of tiles and a round avatar.

Max 5 MB · Images

Uploaded: —
Blade

A dashed box reading "Drag or click to select". Dropping an image on it, or choosing one, shows a tile with its thumbnail, name and size, and a progress bar while Livewire uploads it; $photo then holds the temporary file. A hint under the box tells the accepted types and the size limit, and the tile has buttons to preview and remove the file.

Several files #

Up to five files of up to 10 MB each. Each file is a tile; they can be reordered by dragging, or with Alt and an arrow key, and $docs follows the order. Files over the limits are refused with a message.

Up to 5 files · max 10 MB each · PDF, DOCX

Drag, or press Alt and an arrow key, to move it.
Files: —
Blade

Layouts #

A round avatar with a camera icon that shows the chosen photo; a "Select files" button with each file as a chip under it; an "Add files" button over a list of files with their sizes; and a grid of image tiles.

Drag, or press Alt and an arrow key, to move it.

Max 5 MB each · Images

Drag, or press Alt and an arrow key, to move it.
Blade

One line, and required documents #

inline is a field with the height of an input: a "Select file" button, then the file name (or "No file selected", or "3 files" with multiple), with buttons to view, cancel and remove, and a thin progress bar along its bottom edge while it uploads. document is a card per document: a file icon, the label as title and "Pending" until a file is chosen or stored; then a green border, the file name and buttons to view, replace and remove. Replace only opens the file picker: the file stays until a new one is chosen. With multiple that button adds files instead. Both take files dropped on them.

Max 20 MB · PDF

Articles of association

Pending

Tax certificate

Pending

Bank details

Pending

Blade

Files already stored #

A path (or a list of paths) on the disk is shown as an existing file, with its preview. With stored, only paths under that directory are looked up, so a path sent back by the browser cannot point anywhere else on the disk.

Blade

Hint and drop area #

hint replaces the text built from the limits (false removes it), droppable set to false only opens the file dialog, and the slot replaces the content of the drop area.

Signed PDF, up to 5 MB.

Blade

Field props and states #

description, help and size work as on any field; disabled blocks the area.

Shown at the top of the article.

Max 5 MB · Images

At least 1200 × 630 pixels.

Blade

Customization #

Classes go to the element around everything; prefixed attributes reach the drop area (dropzone:), each tile (tile:) and the hint (hint:).

Drag, or press Alt and an arrow key, to move it.
Blade

Reference

tk:upload

Prop Type Default Description
variant string dropzone dropzone, button, list, gallery, avatar, inline (one line, the height of an input) or document (a card for a required document, with its label as title and a pending or sent state).
multiple bool false Lets several files be chosen. Off for avatar.
accept string null Accepted types, as the native attribute: image/*, .pdf,.docx...
maxSize int per type The size limit in KB, up to the configured limit for each kind of file (tallkit.upload.max_size), which applies without it.
maxFiles int null How many files can be chosen, with multiple.
droppable bool true Accepts files dropped on the area.
sortable bool with multiple Lets the files be reordered. Not for button and avatar.
hint string | false from the limits The text under the area: a string replaces the one built from the limits, false removes it.
disk string the configured disk The disk where stored paths are looked up.
stored string | bool false Shows stored paths only when they are under this directory (true: the upload directory). false shows any path given.

Also accepts the field props (label, description, help, value, size, color...). wire:model binds the uploaded file (or an array of them) through Livewire's file uploads; a native form sends the files under the field's name.

Slots

Slot Description
default Content inside the drop area, in place of its default text and icon.

Prefixes

Prefix Goes to
control: The element around everything: input, drop area, hint and modal.
dropzone: The drop area (the box, the button or the avatar circle).
tile: Each file's tile, chip or list item.
progress: The overall progress bar, shown while several files upload.
preview: The photo inside the avatar variant.
error-message: The error under the avatar variant.
hint: The text under the area.
modal: The preview modal.

Customization

Classes go to the element around everything (the one control: reaches) and other attributes to the file input. Besides the prefixes of the field props (listed in the Reference above).

blade

Accessibility

The native file input, visually hidden, takes the focus and opens the file dialog with Enter or Space; the drop area shows its focus. Files added, removed, rejected or moved are announced in a live region. Reordering works from the keyboard with Alt and the arrow keys, and each file's buttons are named with the file ("View photo.png", "Replace photo.png", "Cancel upload of photo.png", "Retry upload of photo.png", "Remove photo.png"), and the avatar's progress is named "Upload progress". Removing a file moves the focus to the next one, or back to the input. View opens the preview modal for images, videos, audio and PDFs, named by the file; other files open in a new tab. A disabled upload also ignores dropped files.

Behavior notes

  • Removing a file uploaded through Livewire also removes the temporary upload.
  • Without multiple, a new file that breaks a limit (size, type) is listed with its error next to the current one, which is kept; a valid one replaces it.
  • Files dropped on a listed file are added as on the drop area (without multiple, they replace the file). Folders are left out, and dragging anything other than files does not highlight the area.
  • Without sortable, dragging a preview image does not reorder the files.
  • Inside a Livewire component, the bound property is the value; value shows stored files when there is no binding.
  • Paths sent back by the browser are only looked up when the server rendered them before, so a crafted path cannot reveal another file. The check sees only what the browser sent to this component: a path that reaches the property another way (a #[Reactive] or #[Modelable] property filled by a parent, or a method that takes it as an argument) is looked up as given, so use stored there.
  • A PDF shows its file icon in the tile; the document itself is shown only in the preview modal. tk:upload.preview embeds PDFs unless :embed-pdf="false", which the tiles pass.

Storing and pruning uploads

The field only uploads; storing the files is up to the app. A field that already has stored files holds a mix: the paths kept (strings) and the new files (Livewire's temporary files, or the request's files in a native form). uploadKept() keeps only the paths that were really stored before, so a path written by the browser is dropped, and uploadPrune() deletes from the disk the paths that are gone.

php
  • $this->uploadKept($original, $current, $disk = null) and $this->uploadPrune($original, $current, $disk = null) are Livewire component macros; outside Livewire call TALLKit::uploadKept() and TALLKit::uploadPrune(). uploadPrune() returns the deleted paths and fails on a disk that is not configured.
  • TALLKit::uploadRules($field, type:, maxSize:, maxFiles:, multiple:, original:, disk:) returns the rules for the field: the allowed extensions of type (from tallkit.upload.allowed_extensions), its size limit, and, with multiple, an array of at most maxFiles. A path in original passes as it is. The rule itself is new TALLKit\Rules\Upload($rules, $original, $disk, $type, $maxSize), where $rules must have a mimes: or mimetypes: rule as its own array item (not inside a | string) and $original the stored paths (not a boolean).
  • Outside Livewire, the stored files the user kept arrive in <name>_kept[] (photos_kept[], or photo_kept[] for a single file) and the new ones under name:
php

The editors send their files to tallkit.upload.route through a signed link in the page. It lasts tallkit.upload.url_ttl minutes and works only for the user it was made for: another signed-in user gets a 403, a guest a 401. An editor with guest gets a link anyone with the page can use, for guest_url_ttl minutes; the server then accepts only the kinds in tallkit.upload.guest_types and files up to guest_max_size KB, even on a link the app signed itself. null in either key lifts that limit. On a link signed with a size per type, a file of a kind the map does not name gets the smallest size in it.

The images and videos the editors (Quill, Tiptap, TinyMCE) send to the upload route are stored under tallkit.upload.directory as soon as they are inserted. php artisan tallkit:prune-uploads deletes the ones nothing uses anymore (older than --days, 1 by default; --disk, --dry-run), only inside that directory. It refuses to run until the app tells it which files are in use, in a service provider:

php

The callback receives a chunk of candidate paths and must return the ones in use. TALLKit::editorUploadPaths($html, $disk = null) reads the paths of the upload directory from an editor's HTML: src, href, poster and every candidate of srcset, including absolute URLs on another host (www., an old APP_URL).

Never add svg, html or js to tallkit.upload.allowed_extensions or tallkit.upload.file_types when the disk is public: served from your domain, those files run scripts (stored XSS).