### Installation and Initialization: Laravel FileManager Source: https://context7.com/miladimos/laravel-filemanager/llms.txt This section details the command-line steps required to install and initialize the Laravel FileManager package. It covers composer installation, service provider registration, publishing configuration, initializing the file manager structure, running migrations, and setting up storage links. ```bash # 1. Install via Composer composer require miladimos/laravel-filemanager # 2. Add to config/app.php (if not using auto-discovery) # In providers array: Miladimos\FileManager\Providers\FileManagerServiceProvider::class, # In aliases array: 'FileManager' => Miladimos\FileManager\Facades\FileManagerFacade::class, # 3. Publish configuration and run installation php artisan filemanager:install # 4. Configure storage settings in config/filemanager.php # Set 'disk' and 'base_directory' options # 5. Initialize file manager (creates base directory structure) php artisan filemanager:init # 6. Run migrations to create database tables php artisan migrate # 7. If using public disk, create storage symlink php artisan storage:link # 8. Optional: Configure FTP in config/filesystems.php 'ftp' => [ 'driver' => 'ftp', 'host' => 'ftp.example.com', 'username' => 'your-username', 'password' => 'your-password', 'port' => 21, 'root' => '', 'passive' => true, 'ssl' => true, 'timeout' => 30 ], # 9. Optional: Configure SFTP in config/filesystems.php 'sftp' => [ 'driver' => 'sftp', 'host' => 'example.com', 'username' => 'your-username', 'password' => 'your-password', 'privateKey' => '/path/to/privateKey', 'port' => 22, 'root' => '', 'timeout' => 30 ] ``` -------------------------------- ### Run File Manager Installation Command Source: https://github.com/miladimos/laravel-filemanager/blob/master/README-en.md This command initiates the installation process for the laravel-filemanager package, setting up necessary configurations and resources within your Laravel project. ```bash php artisan filemanager:install ``` -------------------------------- ### Configuration Setup: Laravel FileManager Source: https://context7.com/miladimos/laravel-filemanager/llms.txt This PHP configuration file allows customization of the Laravel FileManager's behavior, including storage disk, routes, upload constraints, file type restrictions, and access control rules. It uses environment variables for dynamic settings. ```php // config/filemanager.php return [ // Base directory for all file manager operations 'base_directory' => env('FILEMANAGER_BASE_DIR', 'filemanager'), // Storage disk to use (local, public, s3, ftp, sftp) 'disk' => env('FILEMANAGER_DISK', 'local'), // Route configuration 'routes' => [ 'prefix' => env('FILEMANAGER_ROUTE_PREFIX', 'filemanger'), 'api' => [ 'api_prefix' => env('FILEMANAGER_API_PREFIX', 'api'), 'middleware' => ['api'] ] ], // Upload constraints 'max_file_size' => 1024 * 1024 * 10, // 10MB 'max_image_width' => 1024, 'max_image_height' => 1024, 'image_quality' => 80, // Upload strategies with path templates 'strategies' => [ 'file' => [ 'path' => 'files/{Y}/{m}/{d}/timestamp-$originalFilename', 'date_time_prefix' => true, 'max_size' => '2m' ], 'thumbnail' => [ 'path' => 'thumbnails/{Y}/{m}/{d}/timestamp-$originalFilename', 'height' => 60, 'width' => 60, 'fit' => 'crop' ], 'avatar' => [ 'path' => 'avatars/{Y}/{m}/{d}/timestamp-$originalFilename', 'height' => 250, 'width' => 250, 'fit' => 'stretch', 'sizes' => ['16', '24', '32', '64', '128', '320'], 'thumb' => '320' ] ], // Allowed file types 'allowed_extensions' => [ 'jpeg', 'jpg', 'png', 'gif', 'webp', 'pdf', 'docx', 'xlsx', 'txt', 'csv', 'zip', 'mp4', 'mp3' ], 'allowed_mimes' => [ 'image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/zip' ], // Disallowed extensions for security 'disallow_extensions' => ['exe', 'asm', 'bin', 'o', 'jar'], // Download link expiration in minutes 'download_link_expire' => 10, // ACL rules for access control 'aclRules' => [ 1 => [ ['disk' => 'public', 'path' => 'images/*', 'access' => 2] ] ] ]; ``` -------------------------------- ### Install laravel-filemanager using Composer Source: https://github.com/miladimos/laravel-filemanager/blob/master/README-en.md This snippet shows how to add the laravel-filemanager package to your Laravel project using Composer. It's the first step in integrating the file management capabilities. ```bash composer require miladimos/laravel-filemanager ``` -------------------------------- ### Create Directory API Endpoint - PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Demonstrates how to create a new directory using the Laravel FileManager API. This involves sending a POST request with directory details. It shows examples using cURL and Laravel's HTTP client, including expected success and error responses. ```php use Illuminate\Support\Facades\Http; $response = Http::asForm()->post('http://yourdomain.test/api/filemanger/directories', [ 'name' => 'my-directory', 'description' => 'My project files', 'parent_id' => 0 ]); if ($response->successful()) { $data = $response->json(); } ``` -------------------------------- ### Directory Service Programmatic Usage - PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Shows how to interact with the Laravel FileManager's DirectoryService directly within your Laravel application for backend operations. This includes creating, listing (including recursively), getting info, renaming, and deleting directories. ```php use Miladimos\FileManager\Services\DirectoryService; use Miladimos\FileManager\Models\Directory; // Initialize service $service = new DirectoryService(); // Create a new directory $result = $service->createDirectory([ 'name' => 'uploads', 'description' => 'User uploaded files', 'parent_id' => 0 ]); // List directories in a path $directory = Directory::where('name', 'uploads')->first(); $dirs = $service->listDirectories($directory); // List directories recursively $allDirs = $service->listDirectories($directory, true); // Get directory information with files and subdirectories $info = $service->directoryInfo($directory); echo "Total items: " . $info['itemsCount']; foreach ($info['subFolders'] as $folder) { echo "Folder: " . $folder['name']; } foreach ($info['files'] as $file) { echo "File: " . $file['name'] . " (" . $file['human_size'] . ")"; } // Delete directory (must be empty) $deleted = $service->deleteDirectory($directory); // Rename directory $renamed = $service->renameDirectory($directory, 'new-uploads-folder'); ``` -------------------------------- ### Use FileManager Facade for File Uploads in PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Access file manager functionalities, such as uploading files, using the convenient FileManager facade. This simplifies interactions with the file manager service. The facade provides a direct interface to the underlying FileManager class methods. Example usage is shown within a Laravel controller to handle file uploads from an HTTP request. ```php use FileManager; // Using the facade for quick access $result = FileManager::uploadFile($file, $directory); // The facade provides access to the main FileManager class // Available methods depend on FileManager class implementation // Example usage in controller namespace App\Http\Controllers; use Illuminate\Http\Request; use FileManager; class DocumentController extends Controller { public function store(Request $request) { $file = $request->file('document'); // Use facade for file operations $uploaded = FileManager::upload($file); return response()->json([ 'success' => true, 'message' => 'Document uploaded successfully' ]); } } ``` -------------------------------- ### Register FileManagerServiceProvider in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README-en.md After installing the package, you need to register the FileManagerServiceProvider in your Laravel application's configuration file (config/app.php). This makes the package's features available. ```php Miladimos\FileManager\Providers\FileManagerServiceProvider::class ``` -------------------------------- ### Delete Directory API Endpoint - PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Illustrates how to delete one or multiple directories via the Laravel FileManager API. It provides examples for deleting a single directory and multiple directories in bulk using DELETE requests with cURL. Includes expected success and error responses. ```php // Delete single directory curl -X DELETE http://yourdomain.test/api/filemanger/directories/550e8400-e29b-41d4-a716-446655440000 \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "directories=550e8400-e29b-41d4-a716-446655440000" // Delete multiple directories curl -X DELETE http://yourdomain.test/api/filemanger/directories/bulk \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "directories[]=550e8400-e29b-41d4-a716-446655440000" \ -d "directories[]=660e8400-e29b-41d4-a716-446655440001" ``` -------------------------------- ### PHP - Get Directory Breadcrumb for Navigation Source: https://github.com/miladimos/laravel-filemanager/blob/master/src/Http/Controllers/backup-code.txt This PHP function retrieves directory information required for building a breadcrumb navigation. It takes a folder ID as input, fetches the corresponding directory record, and iteratively fetches its parent directories until the root folder (parent_folder = 0) is reached. The function depends on the `Directory` Eloquent model and the `Request` object. It returns the collected directory data as a JSON string or null if no folder ID is provided. ```php public function getDirectoryBreadcrumb(Request $request) { // This probably could be better. $id = $request->input('folder'); if ($id != 0) { // Get the current folder $folders = Directory::where('id', $id)->get(); // See if it has a parent $parentId = $folders[0]["parent_folder"]; if ($parentId != 0) { $looping = true; while ($looping) { // Get the parent details. $nextDirectory = Directory::where('id', $parentId)->get(); $parentId = $nextDirectory[0]["parent_folder"]; $folders = $folders->merge($nextDirectory); $looping = $parentId != 0; } } return $folders->toJson(); } return null; } ``` -------------------------------- ### Image Service Initialization (PHP) Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Shows how to create an instance of the ImageService. This service is intended for image-related operations within the file manager. It is part of the MiladimosFileManager package. ```php use Miladimos\FileManager\Services\ImageService; $service = new ImageService(); ``` -------------------------------- ### Initialize Laravel File Manager Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Initializes the file manager by running the artisan command. This step is crucial after configuring storage and base directory settings. ```php php artisan filemanager:init ``` -------------------------------- ### File Service Initialization in Laravel File Manager Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Shows how to instantiate the FileService, which is used for various file manipulation operations within the Laravel File Manager. ```php use Miladimos\FileManager\Services\FileService; $service = new FileService(); // or resolve(FileService::class) ``` -------------------------------- ### Upload Service Initialization (PHP) Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Illustrates the instantiation of the UploadService. This service is responsible for handling file uploads within the Laravel File Manager. It belongs to the MiladimosFileManager package. ```php use Miladimos\FileManager\Services\UploadService; $service = new UploadService(); ``` -------------------------------- ### FileGroup Service Usage (PHP) Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Demonstrates how to instantiate and use the FileGroupService to manage file groups. It covers methods for retrieving all file groups, creating, updating, and deleting individual file groups. The service is part of the MiladimosFileManager package. ```php use Miladimos\FileManager\Services\FileGroupService; $service = new FileGroupService(); $service->allFileGroups(); $service->createFileGroup(array $data); // $data = ['title', 'description'] $service->updateFileGroup(FileGroup $fileGroup, array $data); // $data = ['title', 'description'] $service->deleteFileGroup(FileGroup $fileGroup); ``` -------------------------------- ### Directory Service Operations in Laravel File Manager Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Demonstrates the usage of the DirectoryService for managing directories, including creating, deleting, and listing directories recursively. ```php use Miladimos\FileManager\Services\DirectoryService; $service = new DirectoryService(); $service->createDirectory($name); // name of directory for create $service->deleteDirectory($uuid); // uuid of directory for delete in db and disk $service->listDirectories($path) // list all directories in given path $service->listDirectoriesRecursive($path); // list all directories in given path Recursively ``` -------------------------------- ### Directories API Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Endpoints for managing directories, including creating and deleting them. ```APIDOC ## POST /api/prefix/filemanager_api_version/route_prefix/directories ### Description Stores a new directory. ### Method POST ### Endpoint /api/prefix/filemanager_api_version/route_prefix/directories ### Headers Content-Type: application/x-www-form-urlencoded ### Request Body (No specific fields mentioned, assumes directory information is handled) ### Response (Success response details not provided in the source text) ## DELETE /api/prefix/filemanager_api_version/route_prefix/directories ### Description Deletes one or more directories. ### Method DELETE ### Endpoint /api/prefix/filemanager_api_version/route_prefix/directories ### Headers Content-Type: application/x-www-form-urlencoded ### Request Body - **directories** (array or string) - Required - An array of directory UUIDs or a single directory UUID for deletion. ``` -------------------------------- ### API Endpoints for Directory Management Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Details the API endpoints for managing directories. Includes the HTTP method, route, and the expected request body for creating and deleting directories. Requires 'Content-Type: application/x-www-form-urlencoded' header. ```http prefix = /api_prefix/filemanager_api_version/route_prefix // Directories POST -> prefix/directories // store new directory DELETE -> prefix/directories // receive directories field: it can be array of uuid or one uuid of directories for delete ``` -------------------------------- ### Create Database Tables for File Manager Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Executes the database migrations required by the laravel-filemanager package. This command creates the necessary tables in your database. ```php php artisan migrate ``` -------------------------------- ### Upload Files using Uploader Class in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README-en.md Demonstrates how to use the Uploader class to upload files in Laravel. It covers uploading to the default storage, a specified path, and a specific storage, with options for resizing images. ```php public function store(Request $request) { // This will upload your file to the default folder of selected in config storage Uploader::uploadFile($request->file('some_file')); // This will upload your file to the given as second parameter path of default storage Uploader::uploadFile($request->file('some_file'), 'path/to/upload'); // This will upload your file to the given storage Uploader::uploadFile($request->file('some_file'), 'path/to/upload', 'storage_name'); // This will also resize image to the given width and height Uploader::uploadFile($request->file('some_file'), 'path/to/upload', 'storage_name'); } ``` -------------------------------- ### Configure SFTP Filesystem Disk in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Adds an SFTP driver configuration to your config/filesystems.php file, supporting both password and SSH key-based authentication. ```php 'sftp' => [ 'driver' => 'sftp', 'host' => 'example.com', 'username' => 'your-username', 'password' => 'your-password', // Settings for SSH key based authentication... 'privateKey' => '/path/to/privateKey', 'password' => 'encryption-password', // Optional SFTP Settings... // 'port' => 22, // 'root' => '', // 'timeout' => 30, ] ``` -------------------------------- ### Configure FTP Filesystem Disk in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Adds an FTP driver configuration to your config/filesystems.php file. This allows the application to use FTP for storing and retrieving files. ```php 'ftp' => [ 'driver' => 'ftp', 'host' => 'ftp.example.com', 'username' => 'your-username', 'password' => 'your-password', // Optional FTP Settings... // 'port' => 21, // 'root' => '', // 'passive' => true, // 'ssl' => true, // 'timeout' => 30, ] ``` -------------------------------- ### POST /api/filemanger/directories - Create Directory Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Creates a new directory in the file manager system. You can specify the directory name, an optional description, and a parent directory ID. ```APIDOC ## POST /api/filemanger/directories ### Description Creates a new directory in the file manager system with optional parent directory and description. ### Method POST ### Endpoint /api/filemanger/directories ### Parameters #### Request Body - **name** (string) - Required - The name of the directory to create. - **description** (string) - Optional - A description for the directory. - **parent_id** (integer) - Optional - The ID of the parent directory. Defaults to 0 for the root directory. ### Request Example ```json { "name": "my-directory", "description": "My project files", "parent_id": 0 } ``` ### Response #### Success Response (201 Created) - **message** (string) - Confirmation message. - **status** (string) - Status of the operation (e.g., "Created"). #### Response Example ```json { "message": "Directory created successfully", "status": "Created" } ``` ``` -------------------------------- ### Integrate Event System for File Uploads with PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Listen to file manager events, specifically 'AfterUpload', to perform custom processing after a file has been successfully uploaded. This involves creating an event listener class and registering it in the EventServiceProvider. Dependencies include the Laravel framework and the FileManager package. The listener receives an event object containing file information, allowing for actions like logging or triggering notifications. ```php // Create event listener - app/Listeners/ProcessAfterUpload.php namespace App\Listeners; use Miladimos\FileManager\Events\Upload\AfterUpload; use Illuminate\Contracts\Queue\ShouldQueue; class ProcessAfterUpload implements ShouldQueue { public function handle(AfterUpload $event) { // Custom processing after file upload // Access file information from $event \Log::info('File uploaded successfully'); // Trigger notifications, virus scanning, etc. } } // Register in EventServiceProvider - app/Providers/EventServiceProvider.php use Miladimos\FileManager\Events\Upload\AfterUpload; use App\Listeners\ProcessAfterUpload; protected $listen = [ AfterUpload::class => [ ProcessAfterUpload::class, ], ]; // Alternative: Using event listeners inline use Illuminate\Support\Facades\Event; Event::listen( 'Miladimos\FileManager\Events\Upload\BeforeUpload', function ($event) { // Validate file before upload // Perform security checks } ); ``` -------------------------------- ### API Endpoints for File Group Management Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Outlines the API endpoints for managing file groups. Covers retrieving all groups, creating, updating, and deleting file groups, along with the expected request data. Requires 'Content-Type: application/x-www-form-urlencoded' header. ```http prefix = /api_prefix/filemanager_api_version/route_prefix // File Groups GET -> prefix/filegroups // return all available file groups POST -> prefix/filegroups // store new file groups -> receive : title, description PUT -> prefix/filegroups/{filegroup}/update // update file groups -> receive : title, description DELETE -> prefix/filegroups/{filegroup} // delete file groups ``` -------------------------------- ### Link Storage Directory in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Creates a symbolic link from public/storage to the storage/app/public directory. This command is necessary if you are using the public disk for file storage. ```php php artisan storage:link ``` -------------------------------- ### FileGroup Service Usage in PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Programmatic interaction with file group management using the FileGroupService. This service provides methods to retrieve, create, update, and delete file groups within the application. It depends on the FileGroupService class and FileGroup model. ```php use Miladimos\FileManager\Services\FileGroupService; use Miladimos\FileManager\Models\FileGroup; $service = new FileGroupService(); // Get all file groups $allGroups = $service->allFileGroups(); foreach ($allGroups as $group) { echo $group->title . ": " . $group->description; } // Create a new file group $created = $service->createFileGroup([ 'title' => 'User Avatars', 'description' => 'Profile pictures for users' ]); // Update existing file group $fileGroup = FileGroup::find(1); $updated = $service->updateFileGroup($fileGroup, [ 'title' => 'Updated Group Name', 'description' => 'New description for the group' ]); // Delete file group $deleted = $service->deleteFileGroup($fileGroup); ``` -------------------------------- ### Image Service Operations in PHP Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Utilize the ImageService for image manipulation tasks such as resizing, cropping, and format conversion. This service leverages the Intervention Image library. It requires an Image instance and specific parameters for desired transformations. ```php use Miladimos\FileManager\Services\ImageService; use Intervention\Image\Facades\Image; $service = new ImageService(); // Resize image with different fit options $image = Image::make('/path/to/image.jpg'); // Stretch fit $resized = $service->makeImage($image, [ 'width' => 800, 'height' => 600, 'fit' => 'stretch' ]); // Crop fit $cropped = $service->makeImage($image, [ 'width' => 400, 'height' => 400, 'fit' => 'crop', 'x' => 50, // Optional crop position 'y' => 50 ]); // Contain fit (with canvas) $contained = $service->makeImage($image, [ 'width' => 1000, 'height' => 1000, 'fit' => 'contain' ]); // Pad fit (with background color) $padded = $service->makeImage($image, [ 'width' => 800, 'height' => 600, 'fit' => 'pad', 'color' => '#ffffff' ]); // Get preview/thumbnail URL $disk = 'local'; $path = 'filemanager/images/2024/12/19/1734595200-photo.jpg'; $previewResponse = $service->preview($disk, $path); ``` -------------------------------- ### File Upload API and Service Operations (PHP, Curl, JavaScript) Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Upload files or images to the file manager. This snippet demonstrates how to upload files using cURL, JavaScript's Fetch API, and the `UploadService` within a Laravel controller. It handles both regular files and images, with the service automatically prefixing filenames with timestamps. The `directory_id` parameter specifies the target directory for the upload. ```php use Illuminate\Http\Request; use Miladimos\FileManager\Services\UploadService; class MyController extends Controller { public function upload(Request $request, UploadService $uploadService) { $file = $request->file('document'); $directoryId = $request->input('directory_id', 0); // Upload regular file $success = $uploadService->uploadFile($file, $directoryId); // Or upload image with automatic processing $success = $uploadService->uploadImage($file, $directoryId); if ($success) { return response()->json(['message' => 'File uploaded successfully']); } return response()->json(['error' => 'Upload failed'], 500); } } ``` ```curl // API Endpoint: POST /api/filemanger/upload // Upload using curl curl -X POST http://yourdomain.test/api/filemanger/upload \ -H "Content-Type: multipart/form-data" \ -F "file=@/path/to/image.jpg" \ -F "directory_id=1" ``` ```javascript // Using JavaScript/Fetch API const formData = new FormData(); formData.append('file', fileInput.files[0]); formData.append('directory_id', 1); fetch('http://yourdomain.test/api/filemanger/upload', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => console.log('Upload success:', data)) .catch(error => console.error('Upload error:', error)); ``` -------------------------------- ### Configure File Uploads in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README-en.md This snippet shows the configuration file for the laravel-filemanager. Here you can set the default storage, image quality, and the default upload folder for your files. ```php config/file_uploads.php ``` -------------------------------- ### Register Service Provider and Facade in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Registers the FileManagerServiceProvider and FileManagerFacade in the application's config/app.php file. This makes the file manager's functionalities available throughout the application. ```php // in providers Miladimos\FileManager\Providers\FileManagerServiceProvider::class, // in aliases Miladimos\FileManager\Facades\FileManagerFacade::class, ``` -------------------------------- ### File Groups API Source: https://github.com/miladimos/laravel-filemanager/blob/master/README.md Endpoints for managing file groups, including retrieving, creating, updating, and deleting them. ```APIDOC ## GET /api/prefix/filemanager_api_version/route_prefix/filegroups ### Description Returns all available file groups. ### Method GET ### Endpoint /api/prefix/filemanager_api_version/route_prefix/filegroups ### Headers Content-Type: application/x-www-form-urlencoded ### Response #### Success Response (200) - **fileGroups** (array) - A list of file group objects. - **id** (integer) - The unique identifier for the file group. - **title** (string) - The title of the file group. - **description** (string) - The description of the file group. - **created_at** (datetime) - The timestamp when the file group was created. - **updated_at** (datetime) - The timestamp when the file group was last updated. ### Response Example ```json { "fileGroups": [ { "id": 1, "title": "Group 1", "description": "First file group", "created_at": "2023-10-27T10:00:00+00:00", "updated_at": "2023-10-27T10:00:00+00:00" } ] } ``` ## POST /api/prefix/filemanager_api_version/route_prefix/filegroups ### Description Stores a new file group. ### Method POST ### Endpoint /api/prefix/filemanager_api_version/route_prefix/filegroups ### Headers Content-Type: application/x-www-form-urlencoded ### Request Body - **title** (string) - Required - The title of the file group. - **description** (string) - Optional - The description of the file group. ### Request Example ```json { "title": "New Project Files", "description": "Files related to the new project" } ``` ### Response #### Success Response (201) - **message** (string) - Confirmation message. - **fileGroup** (object) - The newly created file group object. - **id** (integer) - The unique identifier for the file group. - **title** (string) - The title of the file group. - **description** (string) - The description of the file group. - **created_at** (datetime) - The timestamp when the file group was created. - **updated_at** (datetime) - The timestamp when the file group was last updated. ### Response Example ```json { "message": "File group created successfully", "fileGroup": { "id": 2, "title": "New Project Files", "description": "Files related to the new project", "created_at": "2023-10-27T10:05:00+00:00", "updated_at": "2023-10-27T10:05:00+00:00" } } ``` ## PUT /api/prefix/filemanager_api_version/route_prefix/filegroups/{filegroup}/update ### Description Updates an existing file group. ### Method PUT ### Endpoint /api/prefix/filemanager_api_version/route_prefix/filegroups/{filegroup}/update ### Path Parameters - **filegroup** (integer|string) - Required - The ID or UUID of the file group to update. ### Headers Content-Type: application/x-www-form-urlencoded ### Request Body - **title** (string) - Optional - The new title for the file group. - **description** (string) - Optional - The new description for the file group. ### Request Example ```json { "title": "Updated Project Files", "description": "Updated description for the new project files" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. - **fileGroup** (object) - The updated file group object. - **id** (integer) - The unique identifier for the file group. - **title** (string) - The title of the file group. - **description** (string) - The description of the file group. - **created_at** (datetime) - The timestamp when the file group was created. - **updated_at** (datetime) - The timestamp when the file group was last updated. ### Response Example ```json { "message": "File group updated successfully", "fileGroup": { "id": 2, "title": "Updated Project Files", "description": "Updated description for the new project files", "created_at": "2023-10-27T10:05:00+00:00", "updated_at": "2023-10-27T10:10:00+00:00" } } ``` ## DELETE /api/prefix/filemanager_api_version/route_prefix/filegroups/{filegroup} ### Description Deletes a file group. ### Method DELETE ### Endpoint /api/prefix/filemanager_api_version/route_prefix/filegroups/{filegroup} ### Path Parameters - **filegroup** (integer|string) - Required - The ID or UUID of the file group to delete. ### Response #### Success Response (200) - **message** (string) - Confirmation message. ### Response Example ```json { "message": "File group deleted successfully" } ``` ``` -------------------------------- ### Image Service Operations Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Operations for processing and manipulating images, including resizing, cropping, and generating preview URLs. ```APIDOC ### Image Service Usage Access image processing operations programmatically through the `ImageService` class. #### Resizing and Cropping ```php use Miladimos\FileManager\Services\ImageService; use Intervention\Image\Facades\Image; $service = new ImageService(); $image = Image::make('/path/to/image.jpg'); // Stretch fit $resizedStretch = $service->makeImage($image, [ 'width' => 800, 'height' => 600, 'fit' => 'stretch' ]); // Crop fit $cropped = $service->makeImage($image, [ 'width' => 400, 'height' => 400, 'fit' => 'crop', 'x' => 50, // Optional crop position 'y' => 50 ]); // Contain fit (with canvas) $contained = $service->makeImage($image, [ 'width' => 1000, 'height' => 1000, 'fit' => 'contain' ]); // Pad fit (with background color) $padded = $service->makeImage($image, [ 'width' => 800, 'height' => 600, 'fit' => 'pad', 'color' => '#ffffff' ]); ``` #### Generating Preview URL ```php // Get preview/thumbnail URL $disk = 'local'; $path = 'filemanager/images/2024/12/19/1734595200-photo.jpg'; $previewResponse = $service->preview($disk, $path); ``` ### Parameters for `makeImage` - **image** (Intervention\Image\Image) - Required - The image object to manipulate. - **options** (array) - Required - An array of options for image manipulation: - **width** (int) - Required - The target width. - **height** (int) - Required - The target height. - **fit** (string) - Required - The fit method ('stretch', 'crop', 'contain', 'pad'). - **x** (int) - Optional - The x-coordinate for cropping. - **y** (int) - Optional - The y-coordinate for cropping. - **color** (string) - Optional - The background color for 'pad' fit (e.g., '#ffffff'). ### Parameters for `preview` - **disk** (string) - Required - The storage disk name. - **path** (string) - Required - The path to the image file. ### Response Example for `preview` ```json { "url": "/storage/filemanager/images/2024/12/19/1734595200-photo.jpg" } ``` ``` -------------------------------- ### File Service Operations Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Utilize the FileService to perform various file operations programmatically. ```APIDOC ## FileService Operations ### Description Perform file operations including rename, move, copy, and delete through the FileService. ### Methods - **rename(File $file, string $newName)**: Renames the given file. - **moveFile(File $file, Directory $targetDirectory)**: Moves the given file to a target directory. - **copyFile(File $file, Directory $targetDirectory)**: Copies the given file to a target directory. - **deleteFile(File $file)**: Deletes the given file. - **getUserFiles(int $userId, int $directoryId = 0)**: Retrieves files for a specific user, optionally filtered by directory. - **generateLink(string $fileUuid)**: Generates a temporary download link for a file. ### Usage Example ```php use Miladimos\FileManager\Services\FileService; use Miladimos\FileManager\Models\File; use Miladimos\FileManager\Models\Directory; $service = new FileService(); // Rename a file $file = File::where('uuid', '550e8400-e29b-41d4-a716-446655440000')->first(); $success = $service->rename($file, 'new-filename.jpg'); // Move file to different directory $targetDir = Directory::find(2); $moved = $service->moveFile($file, $targetDir); // Copy file to another directory $copied = $service->copyFile($file, $targetDir); // Delete a file $deleted = $service->deleteFile($file); // Get user files $userId = auth()->id(); $directoryId = 1; // or 0 for all directories $userFiles = $service->getUserFiles($userId, $directoryId); // Generate temporary download link with expiration $downloadLink = $service->generateLink($file->uuid); // Returns: http://yourdomain.test/filemanager/download/uuid?mac=hash&t=timestamp echo "Download link (expires in 10 minutes): " . $downloadLink; ``` ``` -------------------------------- ### File Service Operations (PHP) Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Perform file operations such as renaming, moving, copying, and deleting using the `FileService` class. This snippet also shows how to retrieve user files and generate temporary download links with an expiration timestamp. It requires instances of `FileService`, `File`, and `Directory` models. ```php use Miladimos\FileManager\Services\FileService; use Miladimos\FileManager\Models\File; use Miladimos\FileManager\Models\Directory; $service = new FileService(); // Rename a file $file = File::where('uuid', '550e8400-e29b-41d4-a716-446655440000')->first(); $success = $service->rename($file, 'new-filename.jpg'); // Move file to different directory $targetDir = Directory::find(2); $moved = $service->moveFile($file, $targetDir); // Copy file to another directory $copied = $service->copyFile($file, $targetDir); // Delete a file $deleted = $service->deleteFile($file); // Get user files $userId = auth()->id(); $directoryId = 1; // or 0 for all directories $userFiles = $service->getUserFiles($userId, $directoryId); // Generate temporary download link with expiration $downloadLink = $service->generateLink($file->uuid); // Returns: http://yourdomain.test/filemanager/download/uuid?mac=hash&t=timestamp echo "Download link (expires in 10 minutes): " . $downloadLink; ``` -------------------------------- ### File Upload API Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Upload files or images to the file manager. Files are automatically prefixed with a timestamp. ```APIDOC ## POST /api/filemanger/upload ### Description Upload files or images to the file manager with automatic timestamp prefixing. ### Method POST ### Endpoint /api/filemanger/upload ### Parameters #### Query Parameters - **directory_id** (integer) - Optional - The ID of the directory to upload the file into. Defaults to 0. #### Request Body - **file** (file) - Required - The file to upload. - **directory_id** (integer) - Optional - The ID of the directory to upload the file into. ### Request Example ```bash curl -X POST http://yourdomain.test/api/filemanger/upload \ -H "Content-Type: multipart/form-data" \ -F "file=@/path/to/image.jpg" \ -F "directory_id=1" ``` ### Response #### Success Response (200) - **message** (string) - Indicates successful upload. #### Response Example ```json { "message": "File uploaded successfully" } ``` ``` -------------------------------- ### File Move API Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Move a file from its current directory to a different directory using the REST API. ```APIDOC ## POST /api/filemanger/files/{file}/{directory}/move ### Description Move a file from one directory to another via the REST API. ### Method POST ### Endpoint /api/filemanger/files/{file}/{directory}/move ### Parameters #### Path Parameters - **file** (string) - Required - The unique identifier (UUID) of the file to move. - **directory** (integer) - Required - The ID of the target directory. ### Request Example ```bash curl -X POST http://yourdomain.test/api/filemanger/files/550e8400-e29b-41d4-a716-446655440000/2/move \ -H "Content-Type: application/x-www-form-urlencoded" ``` ### Response #### Success Response (200) - **message** (string) - Confirms successful move. - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "message": "File moved successfully", "status": "success" } ``` ``` -------------------------------- ### File Rename API Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Rename an existing file through the REST API. ```APIDOC ## POST /api/filemanger/files/{file}/rename ### Description Rename an existing file through the REST API. ### Method POST ### Endpoint /api/filemanger/files/{file}/rename ### Parameters #### Path Parameters - **file** (string) - Required - The unique identifier (UUID) of the file to rename. #### Request Body - **new_name** (string) - Required - The new name for the file. ### Request Example ```bash curl -X POST http://yourdomain.test/api/filemanger/files/550e8400-e29b-41d4-a716-446655440000/rename \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "new_name=updated-document.pdf" ``` ### Response #### Success Response (200) - **message** (string) - Confirms successful renaming. - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "message": "File renamed successfully", "status": "success" } ``` ``` -------------------------------- ### FileGroup Management API Endpoints Source: https://context7.com/miladimos/laravel-filemanager/llms.txt API endpoints for creating, reading, updating, and deleting file groups. These endpoints facilitate the organization of files through a RESTful interface. Requires proper API authentication and request formatting. ```shell curl -X GET http://yourdomain.test/api/filemanger/filegroups // Expected Response [ { "id": 1, "uuid": "550e8400-e29b-41d4-a716-446655440000", "title": "Product Images", "description": "Images for product catalog" }, { "id": 2, "uuid": "660e8400-e29b-41d4-a716-446655440001", "title": "Documents", "description": "Legal and business documents" } ] curl -X POST http://yourdomain.test/api/filemanger/filegroups \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "title=Marketing Materials" \ -d "description=Promotional content and branding assets" curl -X PUT http://yourdomain.test/api/filemanger/filegroups/550e8400-e29b-41d4-a716-446655440000/update \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "title=Updated Title" \ -d "description=Updated description" curl -X DELETE http://yourdomain.test/api/filemanger/filegroups/550e8400-e29b-41d4-a716-446655440000 ``` -------------------------------- ### File Move API (Curl) Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Move a file from its current directory to a different directory via the REST API. This is achieved by sending a POST request to `/api/filemanger/files/{file}/{directory}/move`, where `{file}` is the file's identifier and `{directory}` is the target directory's identifier. The response indicates the outcome of the operation. ```curl // API Endpoint: POST /api/filemanger/files/{file}/{directory}/move curl -X POST http://yourdomain.test/api/filemanger/files/550e8400-e29b-41d4-a716-446655440000/2/move \ -H "Content-Type: application/x-www-form-urlencoded" // Response indicates success or failure { "message": "File moved successfully", "status": "success" } ``` -------------------------------- ### Upload Base64 Image using Uploader Class in Laravel Source: https://github.com/miladimos/laravel-filemanager/blob/master/README-en.md Shows how to upload a base64 encoded image string using the Uploader class. Similar to file uploads, it supports default storage, specified paths, and specific storage locations. ```php public function store(Request $request) { // This will upload your file to the default folder of selected in config storage Uploader::uploadBase64Image($request->input('image')); // This will upload your file to the given as second parameter path of default storage Uploader::uploadFile($request->input('image'), 'path/to/upload'); // This will upload your file to the given storage Uploader::uploadFile($request->input('image'), 'path/to/upload', 'storage_name'); // This will also resize image to the given width and height Uploader::uploadFile($request->input('image'), 'path/to/upload', 'storage_name'); } ``` -------------------------------- ### File Delete API Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Delete a file from the system and its associated storage using the REST API. ```APIDOC ## DELETE /api/filemanger/files/{file} ### Description Delete a file from the system and storage via the REST API. ### Method DELETE ### Endpoint /api/filemanger/files/{file} ### Parameters #### Path Parameters - **file** (string) - Required - The unique identifier (UUID) of the file to delete. ### Request Example ```bash curl -X DELETE http://yourdomain.test/api/filemanger/files/550e8400-e29b-41d4-a716-446655440000 \ -H "Content-Type: application/x-www-form-urlencoded" ``` ### Response #### Success Response (200) - **message** (string) - Confirms successful deletion. - **status** (string) - Indicates the status of the operation. #### Response Example ```json { "message": "File deleted successfully", "status": "success" } ``` ``` -------------------------------- ### File Rename API (Curl) Source: https://context7.com/miladimos/laravel-filemanager/llms.txt Rename an existing file through the REST API by sending a POST request to the `/api/filemanger/files/{file}/rename` endpoint. The request body should include the `new_name` parameter with the desired new filename. The response indicates success or failure. ```curl // API Endpoint: POST /api/filemanger/files/{file}/rename curl -X POST http://yourdomain.test/api/filemanger/files/550e8400-e29b-41d4-a716-446655440000/rename \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "new_name=updated-document.pdf" // Expected Response { "message": "File renamed successfully", "status": "success" } ```