PHP code example of idkwhoami / flux-files

1. Go to this page and download the library: Download idkwhoami/flux-files 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/ */

    

idkwhoami / flux-files example snippets




return [
    /*
    |--------------------------------------------------------------------------
    | Default Storage Disk
    |--------------------------------------------------------------------------
    |
    | The default disk to use for file storage.
    |
    */
    'disk' => env('FLUX_FILES_DISK', 'local'),

    /*
    |--------------------------------------------------------------------------
    | File Validation
    |--------------------------------------------------------------------------
    |
    | Configure file upload restrictions and validation rules.
    |
    */
    'validation' => [
        'max_file_size' => env('FLUX_FILES_MAX_SIZE', 10240), // KB
        'allowed_extensions' => [
            'images' => ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'],
            'documents' => ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'],
            'archives' => ['zip', 'rar', '7z', 'tar', 'gz'],
            'audio' => ['mp3', 'wav', 'ogg', 'flac'],
            'video' => ['mp4', 'avi', 'mov', 'wmv', 'flv'],
        ],
        'mime_types' => [
            // Auto-generated based on extensions
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Eloquent Configuration
    |--------------------------------------------------------------------------
    |
    | Configure the ID type for models (bigint, uuid, ulid).
    |
    */
    'eloquent' => [
        'id_type' => env('FLUX_FILES_ID_TYPE', 'bigint'),
    ],

    /*
    |--------------------------------------------------------------------------
    | Multi-tenancy
    |--------------------------------------------------------------------------
    |
    | Enable multi-tenant support for file isolation.
    |
    */
    'multi_tenant' => [
        'enabled' => env('FLUX_FILES_MULTI_TENANT', false),
        'tenant_model' => null, // Your tenant model class
        'tenant_key' => 'tenant_id',
    ],
];

use App\Models\File;

// Get file URL
$url = $file->getUrl();

// Get preview URL (for images)
$previewUrl = $file->getPreviewUrl();

// Check file type
$isImage = $file->isImage();
$isAudio = $file->isAudio();
$isVideo = $file->isVideo();

// Get human-readable size
$size = $file->getHumanReadableSize();

// Relationships
$folder = $file->folder;
$tenant = $file->tenant; // if multi-tenancy enabled

// Scopes
$files = File::byTenant($tenantId)->get();
$images = File::byMimeType('image')->get();
$folderFiles = File::inFolder($folderId)->get();

use App\Models\Folder;

// Get full folder path
$path = $folder->getFullPath();

// Check if folder is ancestor of another
$isAncestor = $folder->isAncestorOf($otherFolder);

// Get all descendants
$descendants = $folder->getDescendants();

// Create subfolder
$subfolder = $folder->createSubfolder('New Folder');

// Relationships
$files = $folder->files;
$children = $folder->children;
$parent = $folder->parent;

// Scopes
$rootFolders = Folder::roots()->get();
$tenantFolders = Folder::byTenant($tenantId)->get();

use Idkwhoami\FluxFiles\Services\FileStorageService;

$storage = app(FileStorageService::class);

// Store file
$file = $storage->store($uploadedFile, $folderId);

// Delete file
$storage->delete($file);

// Move file
$storage->move($file, $newFolderId);

// Copy file
$newFile = $storage->copy($file, $targetFolderId);

// Check if file exists
$exists = $storage->exists($file);

use Idkwhoami\FluxFiles\Services\FileValidationService;

$validator = app(FileValidationService::class);

// Validate file
$isValid = $validator->validateFile($uploadedFile);

// Validate file type
$isValidType = $validator->validateFileType($uploadedFile, ['images']);

// Validate file size
$isValidSize = $validator->validateFileSize($uploadedFile);

// Get validation errors
$errors = $validator->getErrors();

'multi_tenant' => [
    'enabled' => true,
    'tenant_model' => App\Models\Tenant::class,
    'tenant_key' => 'tenant_id',
],

// Get files for current tenant
$files = File::byTenant(auth()->user()->tenant_id)->get();

// Get folders for current tenant
$folders = Folder::byTenant(auth()->user()->tenant_id)->get();

// In your service provider
use Idkwhoami\FluxFiles\Services\FileValidationService;

FileValidationService::addCustomType('custom', [
    'extensions' => ['custom', 'ext'],
    'mime_types' => ['application/custom'],
    'max_size' => 5120, // KB
]);

use Idkwhoami\FluxFiles\Events\FileUploaded;
use Idkwhoami\FluxFiles\Events\FileDeleted;

// In your EventServiceProvider
protected $listen = [
    FileUploaded::class => [
        // Your listeners
    ],
    FileDeleted::class => [
        // Your listeners
    ],
];
bash
php artisan flux-files:install
bash
php artisan migrate
blade
<x-flux-files:file-icon :file="$file" />
<x-flux-files:folder-icon :folder="$folder" />
<x-flux-files:file-item-grid :file="$file" />
<x-flux-files:file-item-table :file="$file" />
<x-flux-files:file-preview :file="$file" />
<x-flux-files:file-size :file="$file" />
<x-flux-files:file-date :file="$file" />
blade
<x-flux-files:drop-zone />
<x-flux-files:upload-progress :files="$files" />
<x-flux-files:file-upload-item :file="$file" />
bash
php artisan vendor:publish --tag=flux-files-views
bash
php artisan flux-files:install
bash
# Publish configuration
php artisan vendor:publish --tag=flux-files-config

# Publish migrations
php artisan vendor:publish --tag=flux-files-migrations

# Publish models
php artisan vendor:publish --tag=flux-files-models

# Publish views
php artisan vendor:publish --tag=flux-files-views

# Publish language files
php artisan vendor:publish --tag=flux-files-lang

# Publish everything
php artisan vendor:publish --tag=flux-files
bash
composer analyse