Appearance
CanUploadFile
Purpose
Adds file upload and deletion helpers to a controller or service.
Methods
uploadFile(...)
php
uploadFile(UploadedFile|array $file, string $path = '', bool $optimize = false): string|arrayBehavior:
- stores files under
public/uploads/{path} - slugifies the base filename
- adds a random suffix
- supports arrays of uploaded files
- optionally auto-orients and optimizes images
Returns:
- URL string for one file
- array of URL strings for multiple files
deleteFile(...)
php
deleteFile(string|array $path): bool|arrayBehavior:
- deletes one local file path or many
deleteFileFromUrl(...)
php
deleteFileFromUrl(string|array $url): bool|arrayBehavior:
- converts stored URLs back into local paths and deletes them
Typical Usage
Used by:
- uploader controller
- TinyMCE upload controller
- any custom file-management flow