Skip to main content

FilePicker

FilePicker widgetFilePicker widget

Browse the filesystem for a single path. It collects the chosen path (a string).

$p->filePicker('list', 'Price list')
->startIn(getcwd()) // Directory to open in (and the floor for ←).
->filesOnly() // Only files are selectable; directories stay navigable.
->extensions(['csv']) // Limit selectable files to these extensions.
->maxSize(5_000_000) // Reject a selected file larger than this many bytes.
->showHidden(); // Show hidden (dot) entries when the browser opens.

Runnable scripts: playground/02-widgets-filepicker.php and filepicker-multiple.php.

Options

NameDescriptionRequiredDefault
startIn()Directory the browser opens in, and the floor it cannot ascend above.NoCurrent directory
filesOnly()Only files are selectable; directories stay navigable.NoFiles and directories
directoriesOnly()Only directories are selectable.NoFiles and directories
extensions()Restrict selectable files to these extensions (dot-less, case-insensitive).NoAll
maxSize()Reject any selected file larger than this many bytes.NoNo limit
showHidden()Show hidden (dot) entries when the browser opens.NoOff
pageSize()Entries shown before the list pages around the cursor.No10

filesOnly() and directoriesOnly() are mutually exclusive - the last one set wins.

Keyboard

KeyAction
/ Move the highlight
Descend into the highlighted directory
Ascend to the parent (never above the start directory)
printable keysFilter the current directory
TabToggle hidden entries
BackspaceDelete a filter character, or ascend when the filter is empty
EnterSelect the highlighted entry if selectable, otherwise descend into the directory
EscCancel

Display modes

In all four display modes - Unicode or ASCII, color on or off:

ANSINo ANSI
UnicodeFile picker: Unicode + ANSIFile picker: Unicode + ANSIFile picker: Unicode + No ANSIFile picker: Unicode + No ANSI
ASCIIFile picker: ASCII + ANSIFile picker: ASCII + ANSIFile picker: ASCII + No ANSIFile picker: ASCII + No ANSI

Type and size constraints

Constrain what counts as a valid pick with ->filesOnly() / ->directoriesOnly(), ->extensions() and ->maxSize(). The active limits show as a hint below the browser, a pick that breaks one is rejected inline when you accept, and the same limits are enforced in headless collection.

$p->filePicker('list', 'Price list')
->filesOnly() // A directory (or a missing path) is not a valid pick.
->extensions(['csv']) // Only .csv files may be chosen.
->maxSize(5_000_000); // Reject a file larger than 5 MB.

A missing path, a directory where a file is required (or the reverse), a disallowed extension, or an oversized file each fail with a message naming the unmet limit.

Multiple selection

Add ->multiple() to accumulate several paths (a list<string>) instead of one: Space toggles the highlighted entry, selections stick as you browse between directories, and Enter accepts them all.

$p->filePicker('lists', 'Price lists')
->multiple()
->startIn(getcwd())
->extensions(['csv']);

FilePicker widget in multiple modeFilePicker widget in multiple mode

ANSINo ANSI
UnicodeFile picker (multiple): Unicode + ANSIFile picker (multiple): Unicode + ANSIFile picker (multiple): Unicode + No ANSIFile picker (multiple): Unicode + No ANSI
ASCIIFile picker (multiple): ASCII + ANSIFile picker (multiple): ASCII + ANSIFile picker (multiple): ASCII + No ANSIFile picker (multiple): ASCII + No ANSI

Selection limits

Bound how many paths a multiple file picker collects with ->minSelections() and ->maxSelections(). The active limit shows as a hint below the browser, an out-of-range selection is rejected inline when you accept, and the same bounds are enforced in headless collection.

$p->filePicker('price_lists', 'Price lists')
->multiple()
->minSelections(2) // Reject fewer than two paths.
->maxSelections(3); // Reject more than three paths.

File picker in multiple mode with selection limitsFile picker in multiple mode with selection limits

ANSINo ANSI
UnicodeSelection limits: Unicode + ANSISelection limits: Unicode + ANSISelection limits: Unicode + No ANSISelection limits: Unicode + No ANSI
ASCIISelection limits: ASCII + ANSISelection limits: ASCII + ANSISelection limits: ASCII + No ANSISelection limits: ASCII + No ANSI

Runnable script: playground/02-widgets-filepicker-multiple-limited.php.