PHP code example of nishthatechnosoft / php-file-manager

1. Go to this page and download the library: Download nishthatechnosoft/php-file-manager 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/ */

    

nishthatechnosoft / php-file-manager example snippets



Dhiraj\PhpFileManager\FileManager;

// Basic configuration
$config = [
    'root_path' => __DIR__ . '/files',
    'password' => 'your-secure-password',
    'max_file_size' => 50 * 1024 * 1024, // 50MB
];

// Initialize and run
$fileManager = new FileManager($config);
$fileManager->run();


return [
    'root_path' => '/path/to/files',
    'password' => 'secure-password-123',
    'max_file_size' => 100 * 1024 * 1024, // 100MB
    'allowed_extensions' => [
        'txt', 'pdf', 'jpg', 'png', 'zip', 'doc', 'xls'
    ],
    'enable_bulk_operations' => true,
    'enable_archive_operations' => true,
];


Dhiraj\PhpFileManager\FileManager;

$config = er->run();

[
    'txt', 'php', 'html', 'css', 'js', 'json', 'xml', 'md', 'log',
    'zip', 'tar', 'gz', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 
    'ppt', 'pptx', 'jpg', 'jpeg', 'png', 'gif', 'svg', 'mp3', 
    'wav', 'mp4', 'avi', 'mov'
]

$fileManager = new FileManager([
    'password' => hash('sha256', 'my-secret-password'),
    'session_name' => 'my_app_filemanager',
]);

$fileManager = new FileManager([
    'allowed_extensions' => ['txt', 'pdf', 'jpg', 'png'],
    'max_file_size' => 10 * 1024 * 1024, // 10MB limit
]);

$fileManager = new FileManager([
    'root_path' => '/var/www/uploads',
    'password' => $_ENV['FILEMANAGER_PASSWORD'],
    'max_file_size' => 200 * 1024 * 1024, // 200MB
    'allowed_extensions' => [
        'pdf', 'doc', 'docx', 'xls', 'xlsx', 
        'jpg', 'jpeg', 'png', 'gif'
    ],
]);

use Dhiraj\PhpFileManager\FileManager;
use Dhiraj\PhpFileManager\Resources\ResourceManager;

$fileManager = new FileManager($config);
$resourceManager = $fileManager->getResourceManager();

// Get CSS content for custom styling
$css = $resourceManager->getCssContent();

// Get JavaScript for custom integration
$js = $resourceManager->getJsContent();

// In a Laravel controller
public function fileManager()
{
    $config = config('filemanager');
    $fileManager = new \Dhiraj\PhpFileManager\FileManager($config);
    
    ob_start();
    $fileManager->run();
    $output = ob_get_clean();
    
    return response($output);
}

// In a Symfony controller
use Dhiraj\PhpFileManager\FileManager;
use Symfony\Component\HttpFoundation\Response;

public function fileManager(): Response
{
    $config = $this->getParameter('filemanager');
    $fileManager = new FileManager($config);
    
    ob_start();
    $fileManager->run();
    $content = ob_get_clean();
    
    return new Response($content);
}


Dhiraj\PhpFileManager\FileManager;

// Create file manager instance
$fileManager = new FileManager([
    'root_path' => '/path/to/your/files',
    'password' => 'your-secure-password'
]);

// Run the application
$fileManager->run();


Dhiraj\PhpFileManager\FileManager;

$config = [
    'root_path' => '/var/www/files',
    'upload_path' => '/var/www/uploads',
    'max_file_size' => 100 * 1024 * 1024, // 100MB
    'allowed_extensions' => ['txt', 'pdf', 'jpg', 'png', 'zip'],
    'password' => 'super-secure-password',
    'session_name' => 'my_file_manager',
    'enable_compression' => true,
    'enable_bulk_operations' => true,
    'enable_archive_operations' => true
];

$fileManager = new FileManager($config);
$fileManager->run();

public function __construct(array $config = [])

public function run(): void                              // Run the application
public function getConfig(): Configuration               // Get configuration instance
public function getAuth(): AuthenticationService        // Get auth service
public function getSecurity(): SecurityService          // Get security service
public function getFileController(): FileController     // Get file controller

public function get(string $key, mixed $default = null): mixed
public function set(string $key, mixed $value): void
public function getRootPath(): string
public function getMaxFileSize(): int
public function getAllowedExtensions(): array
public function isExtensionAllowed(string $filename): bool

public function createFile(string $filename, string $dir): void
public function createFolder(string $foldername, string $dir): void
public function deleteItem(string $item, string $dir): void
public function renameItem(string $oldName, string $newName, string $dir): void
public function copyItem(string $item, string $destination, string $currentDir): void
public function moveItem(string $item, string $destination, string $currentDir): void

public function bulkDelete(array $items, string $dir): void
public function bulkCopy(array $items, string $destination, string $currentDir): void
public function bulkMove(array $items, string $destination, string $currentDir): void

public function createArchiveWithName(string $archiveName, array $items, string $dir): void
public function unarchiveFile(string $archiveFile, string $dir): void
public function unarchiveToPath(string $archiveFile, string $destination, string $conflictResolution, string $currentDir): void
bash
composer 
bash
git clone https://github.com/dhiraj-nishthatechnosoft/php-file-manager.git
cd php-file-manager
composer install
bash
composer