The Brammo Admin plugin includes a built-in File Manager for uploading, browsing, and managing files and images.
Configure the File Manager in your application's configuration under Admin.FileManager:
'Admin' => [
'FileManager' => [
'basePath' => WWW_ROOT,
'topFolders' => ['images', 'files'],
'fileTypes' => [
'files' => ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'],
'images' => ['jpg', 'jpeg', 'png', 'gif', 'webp'],
],
'fileIcons' => [
'pdf' => 'file-earmark-pdf',
'doc' => 'file-earmark-word',
// ... more mappings
'default' => 'file-earmark',
],
'Images' => [
'maxWidth' => 2048,
'maxHeight' => 2048,
'jpegQuality' => 90,
'pngQuality' => 6,
'webpQuality' => 90,
'resizeOnUpload' => true,
],
],
]| Option | Type | Required | Description |
|---|---|---|---|
basePath |
string | Yes | Base filesystem path where files are stored (typically WWW_ROOT) |
topFolders |
array | Yes | Array of top-level folder names accessible in the File Manager |
fileTypes.files |
array | Yes | Allowed file extensions for documents |
fileTypes.images |
array | Yes | Allowed file extensions for images |
fileIcons |
array | No | Map file extensions to Bootstrap Icons names |
| Option | Type | Default | Description |
|---|---|---|---|
maxWidth |
int | 2048 |
Maximum image width in pixels |
maxHeight |
int | 2048 |
Maximum image height in pixels |
jpegQuality |
int | 90 |
JPEG compression quality (1-100) |
pngQuality |
int | 6 |
PNG compression level (0-9) |
webpQuality |
int | 90 |
WebP compression quality (1-100) |
resizeOnUpload |
bool | true |
Automatically resize images exceeding max dimensions on upload |
The File Manager is available at the following routes:
| Route | Action | Description |
|---|---|---|
/admin/filemanager |
index |
Main file browser interface |
/admin/filemanager/browseImages |
browseImages |
Browse images only (used by image picker modals) |
/admin/filemanager/browseFiles |
browseFiles |
Browse files only |
/admin/filemanager/upload |
upload |
Handle file uploads |
/admin/filemanager/createFolder |
createFolder |
Create new folders |
/admin/filemanager/delete |
delete |
Delete files or empty folders |
/admin/filemanager/fixImage |
fixImage |
Resize an existing image to fit max dimensions |
Browse all files and folders. Navigate through the folder structure starting from configured top folders.
Query Parameters:
folder- Current folder path (e.g.,images/products)filter- Filter files by namepage- Pagination page number
Browse only image files. Used internally by the FormHelper image control for AJAX-based image selection. Results are sorted by date (newest first) with 12 items per page.
Supports AJAX requests with a simplified layout for modal display.
Query Parameters:
folder- Current folder pathfilter- Filter files by namepage- Pagination page numbertarget- Target input element ID (used by image picker modals)
Browse only document files (non-images). Similar to browseImages but sorted by date (newest first) with 10 items per page.
Upload files to a specified folder.
Request:
- Method:
POST - Query:
folder- Target folder path - Body:
file(single file) orfiles[](multiple files)
Response (AJAX):
{
"error": false,
"message": "2 file(s) uploaded",
"files": ["image1.jpg", "image2.jpg"]
}Partial Success Response (some files failed):
{
"error": "Invalid file type png",
"errors": ["Invalid file type png"],
"message": "1 file(s) uploaded",
"files": ["image1.jpg"]
}Error Response:
{
"error": "Invalid file type png"
}Create a new subfolder within the current folder.
Request:
- Method:
POST - Query:
folder- Parent folder path - Body:
folder- New folder name
Delete a file or empty folder.
Request:
- Method:
POST - Query:
folder- Current folder pathdeleteFile- Filename to delete, ORdeleteFolder- Folder name to delete (must be empty)
Resize an existing image to fit within the configured max dimensions.
Request:
- Query:
folder- Folder pathfile- Image filename
The File Manager integrates with the FormHelper's image type for seamless image selection:
echo $this->Form->control('image', [
'type' => 'image',
'folder' => 'images/products',
]);See FormHelper Image Control for detailed documentation.
Add the File Manager to your admin sidebar:
'Sidebar' => [
'menu' => [
'FileManager' => [
'title' => __('Files'),
'icon' => 'folder',
'url' => [
'plugin' => 'Brammo/Admin',
'controller' => 'FileManager',
'action' => 'index'
],
],
],
]Link to specific folders or actions:
// Link to images folder
echo $this->Html->link('Manage Images', [
'plugin' => 'Brammo/Admin',
'controller' => 'FileManager',
'action' => 'index',
'?' => ['folder' => 'images']
]);
// Link to files folder
echo $this->Html->link('Manage Documents', [
'plugin' => 'Brammo/Admin',
'controller' => 'FileManager',
'action' => 'index',
'?' => ['folder' => 'files']
]);The File Manager uses ImageMagick (via PHP's Imagick extension) for image processing.
When resizeOnUpload is enabled, uploaded images exceeding the configured max dimensions are automatically resized while maintaining aspect ratio.
Use the "Fix Image" action to resize existing images that exceed the configured dimensions.
Image processing supports:
- JPEG (.jpg, .jpeg) - Configurable quality compression
- PNG (.png) - Configurable compression level
- WebP (.webp) - Configurable quality compression
- GIF (.gif) - Basic support
Ensure the Imagick PHP extension is installed:
# Ubuntu/Debian
sudo apt-get install php-imagick
# macOS with Homebrew
brew install imagemagick
pecl install imagickThe File Manager includes several security measures:
- Path Validation: All paths are validated against configured
topFoldersto prevent directory traversal; null bytes and..sequences are blocked - Path Resolution Validation: Resolved paths are verified via
realpath()to ensure they stay within the configured base directory - Filename Sanitization: Uploaded and user-supplied filenames are sanitized — path separators, null bytes, and traversal sequences are stripped, and unsafe characters are replaced with underscores
- File Type Validation: Only configured file types in
fileTypesare allowed for upload - Authentication: Access requires authentication through the admin panel's authentication system
- Unique Filenames: Uploaded files with duplicate names are automatically renamed (e.g.,
image(1).jpg)