terremoth/php-win32-filepicker

Use native Windows Explorer File Selector to select a file on PHP

v1.0.2 2025-03-06 04:24 UTC

This package is auto-updated.

Last update: 2025-03-11 08:15:56 UTC


README

Calls Windows Explorer to select file(s).

You are able to configure to select 1 or multiple files, filtering by extensions or let the user free to choose any.

Unlocked by the power of PHP's FFI

Not because we must do it, but because we can!

Made by Terremoth with ⚡ & ❤

Test Run Status License Latest Stable Version Total Downloads Dynamic JSON Badge OpenSSF Scorecard

codecov Test Coverage Psalm type coverage Psalm level Codacy Badge Maintainability

Installation

composer require terremoth/php-win32-filepicker

Documentation

require_once 'vendor/autoload.php';

use Terremoth\Win32\FilePicker;

$selectedDirectory = $_SERVER['USERPROFILE'] ?? 'C:\\'; // optional

$fp = new FilePicker($selectedDirectory); // $selectedDirectory can be null without problem.

// all methods below are *optional*:
$fp
    ->selectMultipleFiles()
    ->addExtensionsFilter(['png', 'jpg', 'gif', 'avif', 'webp', 'jpeg', 'ico', 'bmp'])
    ->filterOnlySelectedExtensions()
    ->setDefaultExtensionSearch('png')
;

$selectedFiles = $fp->open();

print_r($selectedFiles);

// if no files were selected, an empty array will be returned 😉

That's it!

See demos/demo.php for this example.