PHP code example of macocci7 / file-selector-prompt

1. Go to this page and download the library: Download macocci7/file-selector-prompt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

macocci7 / file-selector-prompt example snippets


use function Macocci7\FileSelectorPrompt\fileselector;

$path = fileselector('Select a file to import.');

$path = fileselector(
    label: 'Select a file to import.',
    placeholder: 'E.g. ./vendor/autoload.php',
    default: '',
    

$path = fileselector(
    label: 'Select a file to import.',
    placeholder: 'E.g. ./vendor/autoload.php',
    hint: 'Input the file path.',
    validate: fn (string $value) => match (true) {
        !is_readable($value) => 'Cannot read the file.',
        default => null,
    },
);

$path = fileselector(
    label: 'Select a file to import.',
    placeholder: 'E.g. ./vendor/autoload.php',
    hint: 'Input the file path.',
    validate: fn (string $value) => match (true) {
        !is_readable($value) => 'Cannot read the file.',
        default => null,
    },
    transform: fn ($value) => realpath($value),
);

$path = fileselector(
    label: 'Select a file to import.',
    placeholder: 'E.g. ./vendor/autoload.php',
    hint: 'Input the file path.',
    validate: fn (string $value) => match (true) {
        !is_readable($value) => 'Cannot read the file.',
        default => null,
    },
    extensions: [
        '.json',
        '.php',
    ],
);

use function Macocci7\FileSelectorPrompt\form;

$responses = form()
    ->fileselector(
        label: 'Select a file to import.',
        placeholder: 'E.g. ./vendor/autoload.php',
        hint: 'Input the file path.',
        validate: fn (string $value) => match (true) {
            !is_readable($value) => 'Cannot read the file.',
            default => null,
        },
        extensions: [
            '.json',
            '.php',
        ],
    )->submit();