nishthatechnosoft / php-file-manager
A modern, web-based file manager with advanced features like bulk operations, archive handling, and path-based navigation
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.0|^10.0
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2025-07-29 06:56:10 UTC
README
PHP File Manager
[
](L## Sup## - Path-based na- PSR-12 co## Auth## Author
Dhiraj Dhiman
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
---Dhiman**
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
โญ If you find this project useful, please consider giving it a star on GitHub!Comprehensive documentation
Author
Dhiraj Dhiman
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
---- Bulk operations support
- Archive handling (ZIP/TAR.GZ)
- Modern responsive UI
- PSR-12 compliant code
- Comprehensive documentation
Author
Dhiraj Dhiman
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
--- Dhiman**
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
โญ If you find this project useful, please consider giving it a star on GitHub! Dhiman**
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
โญ If you find this project useful, please consider giving it a star on GitHub!ocumentation](https://github.com/dhiraj-nishthatechnosoft/php-file-manager/wiki)
- ๐ Issue Tracker
- ๐ฌ DiscussionsDocumentation
- ๐ Issue Tracker
- ๐ฌ DiscussionsNSE)
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
- Download the latest release
- Extract to your project directory
- 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
- Change Default Password: Always use a strong, unique password
- Restrict File Types: Only allow necessary file extensions
- Set Upload Limits: Configure appropriate file size limits
- Use HTTPS: Always serve over encrypted connections
- Restrict Access: Use
.htaccess
or server config to limit access - 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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
- Issues: GitHub Issues
- Documentation: GitHub Wiki
- Discussions: GitHub Discussions
๐ 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
- Download the latest release from GitHub
- Extract files to your web directory
- 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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
- GitHub: @dhiraj-nishthatechnosoft
- Email: dhiraj@nishthatechnosoft.com
โญ 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
- Change Default Password: Always change the default password in production
- Restrict Access: Consider additional IP-based restrictions
- File Permissions: Set appropriate file system permissions
- HTTPS: Use HTTPS in production environments
- 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
- Permission Denied: Ensure web server has write permissions
- Upload Fails: Check
upload_max_filesize
andpost_max_size
in php.ini - Archive Creation Fails: Ensure ZipArchive extension is installed
- 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