smarterp-dev/file-manager

A comprehensive file management package for Laravel with support for multiple storage backends

Maintainers

Package info

github.com/turbotechlabs/file-manager

pkg:composer/smarterp-dev/file-manager

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-03-30 06:54 UTC

This package is auto-updated.

Last update: 2026-03-30 07:05:24 UTC


README

A comprehensive file management package for Laravel with support for multiple storage backends, remote API integration, and easy file operations.

Features

  • 🚀 Multiple storage backend support (Local, S3, FTP, SFTP)
  • 📤 File upload/download capabilities
  • 🗑️ File deletion operations
  • 📋 File listing and directory operations
  • 📊 File metadata retrieval
  • 🔗 Remote API integration for centralized file management
  • 🔐 Secure file handling
  • 💾 Configurable upload limits and allowed file types
  • ⚙️ Easy Laravel integration with Facade support

Requirements

  • PHP >= 7.4
  • Laravel 6.0, 7.0, 8.0, 9.0, or 10.0
  • Guzzle HTTP Client

Installation

Install the package via Composer:

composer require turbotech/file-manager

The package will be automatically discovered by Laravel.

Publishing Configuration

Publish the configuration file:

php artisan vendor:publish --provider="TurboTech\FileManager\FileManagerServiceProvider" --tag="config"

This will create a config/file-manager.php file in your Laravel project.

Configuration

Edit the .env file to configure the file manager:

FILE_MANAGER_DRIVER=local
FILE_MANAGER_URL=https://your-storage-api.com
FILE_MANAGER_API_KEY=your_api_key_here
FILE_MANAGER_TIMEOUT=30
FILE_MANAGER_VERIFY_SSL=true
FILE_MANAGER_MAX_SIZE=104857600
FILE_MANAGER_CHUNK_SIZE=5242880

Or configure in config/file-manager.php:

return [
    'driver' => 'local',
    'remote' => [
        'url' => env('FILE_MANAGER_URL'),
        'api_key' => env('FILE_MANAGER_API_KEY'),
        'timeout' => 30,
        'verify_ssl' => true,
    ],
    'upload' => [
        'max_size' => 104857600, // 100MB
        'allowed_extensions' => ['jpg', 'jpeg', 'png', 'pdf', 'doc', 'docx'],
        'chunk_size' => 5242880, // 5MB
    ],
    'paths' => [
        'uploads' => 'uploads',
        'temporary' => 'temporary',
        'archives' => 'archives',
    ],
];

Usage

Using the Facade

use TurboTech\FileManager\Facades\FileManager;

// Upload a file
$result = FileManager::upload('/path/to/file.pdf', 'documents');
// Returns: ['success' => true, 'path' => 'file.pdf', 'url' => '...', 'size' => 1024]

// Download a file
$result = FileManager::download('documents/file.pdf', '/local/path/file.pdf');

// Delete a file
$result = FileManager::delete('documents/file.pdf');

// Check if file exists
$exists = FileManager::exists('documents/file.pdf');

// Get file URL
$url = FileManager::getUrl('documents/file.pdf');

// List files in directory
$files = FileManager::listFiles('documents');
$allFiles = FileManager::listFiles('documents', true); // Recursive

// Get file metadata
$metadata = FileManager::getMetadata('documents/file.pdf');
// Returns: ['path' => '...', 'size' => 1024, 'lastModified' => timestamp, 'mimeType' => '...']

// Upload to remote API
$result = FileManager::uploadToRemote('/path/to/file.pdf');

Using Dependency Injection

use TurboTech\FileManager\FileManager;

class DocumentController extends Controller
{
    public function store(Request $request, FileManager $fileManager)
    {
        $result = $fileManager->upload(
            $request->file('document')->getPathname(),
            'documents'
        );

        return response()->json($result);
    }
}

API Reference

upload($filePath, $destinationPath = '', $options = [])

Upload a file to storage.

Parameters:

  • $filePath (string): Path to the file to upload
  • $destinationPath (string): Destination directory path
  • $options (array): Additional storage options

Returns: Array with success status, path, URL, and size

download($filePath, $savePath = null)

Download a file from storage.

Parameters:

  • $filePath (string): Path to the file in storage
  • $savePath (string|null): Local path to save the file

Returns: Array with success status, path, and size

delete($filePath)

Delete a file from storage.

Parameters:

  • $filePath (string): Path to the file to delete

Returns: Array with success status and message

exists($filePath)

Check if a file exists.

Parameters:

  • $filePath (string): Path to the file

Returns: Boolean

getUrl($filePath)

Get the URL of a file.

Parameters:

  • $filePath (string): Path to the file

Returns: File URL as string

listFiles($directory = '', $recursive = false)

List files in a directory.

Parameters:

  • $directory (string): Directory path
  • $recursive (bool): Whether to list recursively

Returns: Array of file paths

getMetadata($filePath)

Get file metadata.

Parameters:

  • $filePath (string): Path to the file

Returns: Array with path, size, lastModified, and mimeType

uploadToRemote($filePath, $options = [])

Upload a file to remote API server.

Parameters:

  • $filePath (string): Path to the file to upload
  • $options (array): Additional options including:
    • endpoint (string): API endpoint path (default: 'upload')

Returns: Array with success status and response data

Headers Sent:

  • x-api-key: API key from configuration
  • Accept: application/json

Example:

$result = FileManager::uploadToRemote('/path/to/file.pdf', [
    'endpoint' => 'api/upload'
]);

Storage Drivers

The package supports the following storage drivers:

  • local - Local filesystem
  • s3 - Amazon S3
  • ftp - FTP Server
  • sftp - SFTP Server

Configure the driver in config/file-manager.php or set FILE_MANAGER_DRIVER in your .env file.

Error Handling

The package throws exceptions for common errors. Always wrap operations in try-catch blocks:

use TurboTech\FileManager\Facades\FileManager;

try {
    $result = FileManager::upload('/path/to/file.pdf');
} catch (Exception $e) {
    Log::error('File upload failed: ' . $e->getMessage());
}

Examples

User Avatar Upload

use TurboTech\FileManager\Facades\FileManager;

class UserController extends Controller
{
    public function updateAvatar(Request $request)
    {
        $request->validate([
            'avatar' => 'required|image|max:2048',
        ]);

        $user = auth()->user();
        
        // Delete old avatar if exists
        if ($user->avatar_path && FileManager::exists($user->avatar_path)) {
            FileManager::delete($user->avatar_path);
        }

        // Upload new avatar
        $result = FileManager::upload(
            $request->file('avatar')->getPathname(),
            "users/{$user->id}/avatar"
        );

        $user->update(['avatar_path' => $result['path']]);

        return response()->json(['success' => true, 'url' => $result['url']]);
    }
}

Document Management

use TurboTech\FileManager\Facades\FileManager;

class DocumentService
{
    public function listUserDocuments($userId)
    {
        $path = "users/{$userId}/documents";
        return FileManager::listFiles($path, true);
    }

    public function storeDocument($userId, $file, $category)
    {
        $destination = "users/{$userId}/documents/{$category}";
        return FileManager::upload($file->getPathname(), $destination);
    }

    public function archiveDocument($documentPath)
    {
        // Get file content
        $metadata = FileManager::getMetadata($documentPath);
        
        // Download to temporary location
        $tempPath = storage_path("temp/" . basename($documentPath));
        FileManager::download($documentPath, $tempPath);
        
        // Process...
        
        return true;
    }
}

Testing

The package includes test support. Create tests using Orchestra Testbench:

use Orchestra\Testbench\TestCase;
use TurboTech\FileManager\Facades\FileManager;

class FileManagerTest extends TestCase
{
    protected function getPackageProviders($app)
    {
        return ['TurboTech\FileManager\FileManagerServiceProvider'];
    }

    public function test_file_upload()
    {
        $tempFile = tempnam(sys_get_temp_dir(), 'test');
        file_put_contents($tempFile, 'test content');

        $result = FileManager::upload($tempFile, 'test');

        $this->assertTrue($result['success']);
        $this->assertNotEmpty($result['path']);
    }
}

License

MIT License. See LICENSE file for details.

Support

For issues, questions, or contributions, please visit the repository or contact the TurboTech development team.

Changelog

Version 1.0.0

  • Initial release
  • File upload/download support
  • Multiple storage backend support
  • Remote API integration
  • Comprehensive configuration options