index.php
Gallery REST API Endpoint
Provides RESTful API for managing a file gallery system with support for file uploads, listing, deletion, and folder management.
Tags
Table of Contents
Constants
- ALLOWED_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg']
- Allowed file extensions for uploads
- GALLERY_ROOT = \dirname(__DIR__, 4) . '/public-files'
- Root directory for gallery files storage Shared location: /var/vhosts/dressapi/public-files
- MAX_UPLOAD_SIZE = 10 * 1024 * 1024
- Maximum file upload size in bytes (10MB)
Functions
- SanitizeOutput() : string
- Sanitizes output to prevent XSS attacks
- ValidatePath() : string
- Validates and normalizes a path to prevent directory traversal attacks
- GetFullPath() : string
- Gets the full safe path by validating and resolving the relative path
- HandleUpload() : void
- Handles file upload requests
- HandleList() : void
- Lists files and folders in a directory
- HandleDelete() : void
- Deletes a file or folder recursively
- HandleRename() : void
- Renames a file or folder in the gallery
- HandleCreateFolder() : void
- Creates a new folder in the gallery
Constants
ALLOWED_EXTENSIONS
Allowed file extensions for uploads
public
array<string|int, mixed>
ALLOWED_EXTENSIONS
= ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg']
GALLERY_ROOT
Root directory for gallery files storage Shared location: /var/vhosts/dressapi/public-files
public
string
GALLERY_ROOT
= \dirname(__DIR__, 4) . '/public-files'
MAX_UPLOAD_SIZE
Maximum file upload size in bytes (10MB)
public
int
MAX_UPLOAD_SIZE
= 10 * 1024 * 1024
Functions
SanitizeOutput()
Sanitizes output to prevent XSS attacks
SanitizeOutput(string|null $string) : string
Parameters
- $string : string|null
-
The string to sanitize
Return values
string —The sanitized string, empty if input is null
ValidatePath()
Validates and normalizes a path to prevent directory traversal attacks
ValidatePath(string $path) : string
Parameters
- $path : string
-
The path to validate
Return values
string —The sanitized path without dangerous characters
GetFullPath()
Gets the full safe path by validating and resolving the relative path
GetFullPath(string $relative_path) : string
Parameters
- $relative_path : string
-
The relative path to resolve
Tags
Return values
string —The full validated path
HandleUpload()
Handles file upload requests
HandleUpload() : void
Tags
Return values
void —Outputs JSON response
HandleList()
Lists files and folders in a directory
HandleList() : void
Tags
Return values
void —Outputs JSON response with list of items
HandleDelete()
Deletes a file or folder recursively
HandleDelete() : void
Tags
Return values
void —Outputs JSON response
HandleRename()
Renames a file or folder in the gallery
HandleRename() : void
Tags
Return values
void —Outputs JSON response with renamed item info
HandleCreateFolder()
Creates a new folder in the gallery
HandleCreateFolder() : void
Tags
Return values
void —Outputs JSON response with created folder info