nishthatechnosoft/php-file-manager

A modern, web-based file manager with advanced features like bulk operations, archive handling, and path-based navigation

v1.0.0 2025-07-29 06:08 UTC

This package is auto-updated.

Last update: 2025-07-29 06:56:10 UTC


README

Latest Version License PHP Version

PHP File Manager

PHP Version [License](L## Sup## - Path-based na- PSR-12 co## Auth## Author

Dhiraj Dhiman

---Dhiman**

โญ If you find this project useful, please consider giving it a star on GitHub!Comprehensive documentation

Author

Dhiraj Dhiman

---- Bulk operations support

  • Archive handling (ZIP/TAR.GZ)
  • Modern responsive UI
  • PSR-12 compliant code
  • Comprehensive documentation

Author

Dhiraj Dhiman

--- Dhiman**

โญ If you find this project useful, please consider giving it a star on GitHub! Dhiman**

โญ If you find this project useful, please consider giving it a star on GitHub!ocumentation](https://github.com/dhiraj-nishthatechnosoft/php-file-manager/wiki)

A modern, feature-rich web-based file manager built with PHP 8.0+. This package provides a complete file management solution with advanced features like bulk operations, archive handling, path-based navigation, and a responsive user interface.

โœจ Features

๐Ÿ” Security

  • Password-based authentication with session management
  • Path traversal protection preventing unauthorized access
  • File type validation with configurable allowed extensions
  • File size limits to prevent abuse
  • CSRF protection and secure session handling

๐Ÿ“ File Operations

  • Create, edit, rename, and delete files and directories
  • Upload files with drag-and-drop support
  • Download files and directories
  • Copy and move items between directories
  • Bulk operations for multiple files/folders

๐Ÿ“ฆ Archive Management

  • Create archives (ZIP format) from selected files/folders
  • Extract archives (ZIP, TAR.GZ, TGZ) to current or custom directory
  • Bulk archive creation for multiple items
  • Archive preview before extraction

๐ŸŽจ Modern Interface

  • Responsive design works on desktop and mobile
  • Path-based navigation with autocomplete suggestions
  • File type icons with visual file identification
  • Drag-and-drop file uploads
  • Real-time feedback with SweetAlert2 notifications

โšก Advanced Features

  • Path autocomplete for quick navigation
  • File size formatting (B, KB, MB, GB)
  • Last modified timestamps
  • Directory breadcrumbs
  • Keyboard shortcuts for common actions

๐Ÿ“ฆ Installation

Via Composer (Recommended)

composer require nishthatechnosoft/php-file-manager

Manual Installation

  1. Download the latest release
  2. Extract to your project directory
  3. Install dependencies: composer install

๐Ÿš€ Quick Start

Basic Usage

<?php
require_once 'vendor/autoload.php';

use 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();

Using Configuration File

Create filemanager-config.php:

<?php
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,
];

Then in your PHP file:

<?php
require_once 'vendor/autoload.php';

use Dhiraj\PhpFileManager\FileManager;

$config = require 'filemanager-config.php';
$fileManager = new FileManager($config);
$fileManager->run();

โš™๏ธ Configuration Options

Option Type Default Description
root_path string $_SERVER['DOCUMENT_ROOT'] Root directory for file operations
upload_path string {root_path}/uploads Directory for file uploads
password string 'admin123' Authentication password
max_file_size integer 52428800 (50MB) Maximum file upload size in bytes
allowed_extensions array See below Array of allowed file extensions
session_name string 'php_file_manager' Session name for authentication
enable_compression boolean true Enable file compression features
enable_bulk_operations boolean true Enable bulk file operations
enable_archive_operations boolean true Enable archive creation/extraction

Default Allowed Extensions

[
    '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'
]

๐ŸŽฏ Usage Examples

Custom Authentication

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

Restricted File Types

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

Production Configuration

$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'
    ],
]);

๐Ÿ›ก๏ธ Security Considerations

  1. Change Default Password: Always use a strong, unique password
  2. Restrict File Types: Only allow necessary file extensions
  3. Set Upload Limits: Configure appropriate file size limits
  4. Use HTTPS: Always serve over encrypted connections
  5. Restrict Access: Use .htaccess or server config to limit access
  6. Regular Updates: Keep the package updated for security patches

Example .htaccess Protection

# Restrict access to file manager
<Files "filemanager.php">
    Require ip 192.168.1.0/24
    # Or require authentication
    # AuthType Basic
    # AuthName "File Manager"
    # AuthUserFile /path/to/.htpasswd
    # Require valid-user
</Files>

๐Ÿ”ง Advanced Usage

Custom Resource Management

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();

Integration with Frameworks

Laravel Integration

// 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);
}

Symfony Integration

// 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);
}

๐ŸŽจ Customization

Custom Styling

Override the default CSS by including your own stylesheet after the package CSS:

<link rel="stylesheet" href="path/to/filemanager-styles.css">
<link rel="stylesheet" href="path/to/your-custom.css">

Custom JavaScript

Extend functionality by adding your own JavaScript:

<script src="path/to/filemanager-script.js"></script>
<script>
// Your custom JavaScript
document.addEventListener('DOMContentLoaded', function() {
    // Custom functionality here
});
</script>

๐Ÿงช Development

Requirements

  • PHP 8.0 or higher
  • Composer
  • Extensions: zip, phar, json, session

Setup Development Environment

git clone https://github.com/dhiraj-nishthatechnosoft/php-file-manager.git
cd php-file-manager
composer install

Running Tests

composer test

Code Style

# Check code style
composer phpcs

# Fix code style
composer fix-cs

# Static analysis
composer phpstan

๐Ÿ“ Changelog

Version 1.0.0

  • Initial release
  • Complete file management functionality
  • PSR-12 compliant code
  • Composer package structure
  • Comprehensive documentation

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Contribution Guidelines

  • Follow PSR-12 coding standards
  • Add tests for new functionality
  • Update documentation as needed
  • Ensure backward compatibility

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with modern PHP practices
  • Uses SweetAlert2 for notifications
  • Inspired by popular file managers
  • Community feedback and contributions

๐Ÿ“ž Support

๐Ÿ”— Links

Made with โค๏ธ by Dhiraj Dhiman

Features

  • ๐Ÿ” Secure Authentication - Password-protected access with session management
  • ๐Ÿ“ File & Folder Operations - Create, rename, delete, copy, and move files/folders
  • ๐Ÿ“ฆ Archive Support - Create and extract ZIP/TAR.GZ archives
  • ๏ฟฝ Bulk Operations - Select and operate on multiple files simultaneously
  • ๐Ÿ›ค๏ธ Path-Based Navigation - Direct path input with auto-suggestions
  • ๐Ÿ“ File Editor - Built-in text editor for code files
  • โฌ†๏ธ File Upload - Drag and drop file uploads
  • ๐ŸŽจ Modern UI - Clean, responsive interface with dark mode support
  • ๐Ÿ” Search & Filter - Quick file search and filtering
  • ๐Ÿ“Š File Information - File sizes, modification dates, and permissions

Installation

Via Composer (Recommended)

composer require nishthatechnosoft/php-file-manager

Manual Installation

  1. Download the latest release from GitHub
  2. Extract files to your web directory
  3. Install dependencies:
    composer install

Quick Start

Basic Usage

<?php
require_once 'vendor/autoload.php';

use 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();

Advanced Configuration

<?php
require_once 'vendor/autoload.php';

use 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();

Configuration Options

Option Type Default Description
root_path string $_SERVER['DOCUMENT_ROOT'] Root directory for file operations
upload_path string {root_path}/uploads Directory for uploaded files
max_file_size int 52428800 (50MB) Maximum file upload size in bytes
allowed_extensions array See config Array of allowed file extensions
password string admin123 Authentication password
session_name string php_file_manager Session variable name
enable_compression bool true Enable/disable compression features
enable_bulk_operations bool true Enable/disable bulk operations
enable_archive_operations bool true Enable/disable archive operations

Security Features

  • Path Validation - Prevents directory traversal attacks
  • File Type Filtering - Configurable allowed file extensions
  • Size Limits - Configurable file size restrictions
  • Session Management - Secure session handling with timeouts
  • Input Sanitization - All user inputs are sanitized
  • CSRF Protection - Cross-Site Request Forgery protection

API Reference

FileManager Class

Constructor

public function __construct(array $config = [])

Methods

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

Configuration Class

Methods

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

FileController Class

File Operations

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

Bulk Operations

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

Archive Operations

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

Frontend Features

Path-Based Navigation

  • Direct path input with / prefix for absolute paths
  • Auto-suggestions while typing paths
  • Keyboard navigation (arrow keys, enter)
  • Automatic directory creation

Bulk Operations

  • Multi-select with checkboxes
  • Keyboard shortcuts (Ctrl+A for select all)
  • Bulk copy, move, delete, and archive operations

File Editor

  • Syntax highlighting for common file types
  • Auto-save functionality
  • Full-screen editing mode

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 11+
  • Edge 16+

Requirements

  • PHP 8.0 or higher
  • PHP Extensions: zip, phar, json
  • Web server (Apache, Nginx, etc.)

Development

Running Tests

composer test

Code Style Check

composer phpcs

Static Analysis

composer phpstan

Fix Code Style

composer fix-cs

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

v1.0.0 (2025-01-29)

  • Initial release
  • Complete file management functionality
  • Path-based navigation system
  • Bulk operations support
  • Archive handling (ZIP/TAR.GZ)
  • Modern responsive UI
  • PSR-12 compliant code
  • Comprehensive documentation

Support

Author

Dhiraj Dhiman

โญ If you find this project useful, please consider giving it a star on GitHub!

  • ๐Ÿ“– Markdown files
  • ๐Ÿ“ฆ Archive files
  • ๐Ÿ–ผ๏ธ Image files
  • ๐ŸŽต Audio files
  • ๐ŸŽฌ Video files
  • ๐Ÿ“„ Other files

Security Considerations

  1. Change Default Password: Always change the default password in production
  2. Restrict Access: Consider additional IP-based restrictions
  3. File Permissions: Set appropriate file system permissions
  4. HTTPS: Use HTTPS in production environments
  5. File Type Validation: The system restricts editable file types for security

Requirements

  • PHP 5.6 or higher
  • Web server (Apache, Nginx, etc.)
  • ZipArchive extension for archive functionality
  • Write permissions on the target directory

Troubleshooting

Common Issues

  1. Permission Denied: Ensure web server has write permissions
  2. Upload Fails: Check upload_max_filesize and post_max_size in php.ini
  3. Archive Creation Fails: Ensure ZipArchive extension is installed
  4. Can't Edit Files: Check if file extension is in ALLOWED_EXTENSIONS array

Error Messages

  • "File not found": File doesn't exist or was moved
  • "Permission denied": Insufficient file system permissions
  • "Upload failed": File too large or upload directory not writable
  • "Archive creation failed": ZipArchive extension not available

License

This project is open source and available under the MIT License.

Contributing

Feel free to submit issues, fork the repository, and create pull requests for any improvements.

Changelog

Version 1.0

  • Initial release
  • Basic file management operations
  • Archive creation functionality
  • Responsive web interface
  • Security features