PHP code example of websk / php-filemanager
1. Go to this page and download the library: Download websk/php-filemanager 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/ */
websk / php-filemanager example snippets
use WebSK\Config\ConfWrapper;
use WebSK\FileManager\FileManager;
$config = s');
ConfWrapper::setConfig([
'storages' => [
'files' => [
'adapter' => 'local',
'root_path' => '/var/www/app/public/files',
'url_path' => '/files',
'allowed_extensions' => ['jpg', 'png', 'pdf'],
'allowed_types' => ['image/jpeg', 'image/png', 'application/pdf'],
],
],
]);
[
'adapter' => 's3',
'bucket' => 'application-files',
'region' => 'eu-central-1',
'url_path' => 'https://application-files.s3.eu-central-1.amazonaws.com',
]
[
'adapter' => 's3',
'bucket' => 'application-files',
'region' => 'eu-central-1',
'url' => 'http://localhost:9000',
'use_path_style_endpoint' => true,
'access_key' => 'access-key',
'secret_key' => 'secret-key',
'connect_timeout' => 2,
'timeout' => 5,
'retries' => 1,
]
[
'adapter' => 'sftp',
'host' => 'sftp.example.com',
'port' => 22,
'username' => 'application',
'password' => null,
'privateKey' => '/run/secrets/sftp_private_key',
'passphrase' => null,
'root' => '/uploads',
'timeout' => 10,
'maxTries' => 4,
'hostFingerprint' => 'SHA256:...',
'useAgent' => false,
]
$error = null;
$fileName = $fileManager->storeUploadedFile(
$_FILES['document'],
'documents/2026',
'',
$error,
);
if ($fileName === '') {
throw new RuntimeException($error ?? 'Upload failed.');
}
$publicUrl = $fileManager->getFileUrl('documents/2026/' . $fileName);
shell
composer