File Management

This document describes the file management subsystem in the Hotelaro codebase. It covers the mechanisms for uploading, validating, and storing files (including images and documents), as well as the related frontend and backend code entities. The focus is on the technical implementation, including single and multi-file upload flows, file validation, and storage conventions.

For information about general-purpose helper functions, see Common Helpers. For details on form submission, validation, and notifications, see Form Handling.

Purpose and Scope

This page documents:

It does not cover:

System Overview

The file management system enables users (typically admins) to upload images and documents through the web interface. Uploaded files are validated, stored in a structured directory under writable/uploads/, and their paths are returned for further use (e.g., displaying images, attaching documents to records).

High-Level Flow Diagram

Key Code Entities

Entity Type Location Description
FileorImageUploadController Controller app/Controllers/FileorImageUploadController.php Handles single and multi-file upload endpoints, validation, and storage.
imageorfileupload.php View/Script app/Views/common_script/imageorfileupload.php Frontend JS for single file/image upload.
multifileuploader.php View/Script app/Views/common_script/multifileuploader.php Frontend JS for multi-file/image upload.
writable/uploads/ Directory (filesystem) Storage location for uploaded files, organized by type.

Backend: File Upload Controller

The main backend logic is implemented in the FileorImageUploadController class.

Endpoints

Validation Logic

Example: Single File Upload Flow

"writable/uploads/"
"FileorImageUploadController"
"Frontend JS"
"writable/uploads/"
"FileorImageUploadController"
"Frontend JS"
POST /singleuploader (file, filetype)
Validate filetype, extension, size
Move file to uploads/{filetype}/
JSON {status, filename, message}
    

Frontend: Upload Scripts

Single File/Image Upload

Multi-File/Image Upload

Example: Multi-File Upload UI Update

File Storage Structure

Uploaded files are stored in the following structure:

writable/
└── uploads/
    ├── image/
    │   └── {random_filename}.png
    └── document/
        └── {random_filename}.pdf
    

The subdirectory is determined by the filetype parameter.

Filenames are randomized to avoid collisions and for security.

File Validation and Error Handling

Validation Step Logic Error Response
File present Checks if file is uploaded 400, "No file was uploaded."
File type Checks filetype param and extension 400, "Invalid file type provided." or "Invalid file format."
File size Max 5 MB 400, "File size exceeds the maximum limit of 5 MB."
File validity Checks for upload errors 400, "Failed to upload the file."

Bridging System Names to Code Entities

Diagram: File Upload System and Code Entities

Example: Integration with Other Systems

Uploaded file paths are typically stored in database fields or used to display images/documents in the admin interface. The file management system is designed to be modular and reusable across different modules (e.g., room images, customer documents).

Security and Best Practices

Summary Table: File Management Endpoints

Endpoint Method Purpose View/Script Controller Method
/singleuploader POST Single file/image upload imageorfileupload.php FileorImageUploadController::singleuploader()
/multiuploader POST Multi-file/image upload multifileuploader.php FileorImageUploadController::multiuploader()

Related Topics