UploaderService
in package
File uploader service Handles secure file uploads with filename sanitization and unique naming
Table of Contents
Properties
- $slugger : SluggerInterface
Methods
- __construct() : mixed
- Constructor
- uploadFile() : string
- Upload a file to the specified directory with secure filename handling
- uploadImageCompressed() : string
- Uploads, resizes, and compresses an image to JPEG format.
Properties
$slugger read-only
private
SluggerInterface
$slugger
Methods
__construct()
Constructor
public
__construct(SluggerInterface $slugger) : mixed
Parameters
- $slugger : SluggerInterface
-
Slugger for filename sanitization
uploadFile()
Upload a file to the specified directory with secure filename handling
public
uploadFile(UploadedFile $file, string $directoryFolder) : string
Parameters
- $file : UploadedFile
-
The uploaded file to process
- $directoryFolder : string
-
Target directory for file upload
Tags
Return values
string —The new filename after upload
uploadImageCompressed()
Uploads, resizes, and compresses an image to JPEG format.
public
uploadImageCompressed(UploadedFile $file, string $directoryFolder[, int $maxDimension = 1600 ][, int $quality = 82 ]) : string
-
- Validates image mime-type (falls back to standard upload if not an image).
- Generates a slugged, unique filename.
- Scales down the image if it exceeds $maxDimension.
- Iteratively reduces JPEG quality to fit under 2MB.
- Supports JPG, PNG, and WebP (if GD webp is enabled).
- @param UploadedFile $file The uploaded file object.
Parameters
- $file : UploadedFile
- $directoryFolder : string
-
Destination directory path.
- $maxDimension : int = 1600
-
Maximum width/height in pixels.
- $quality : int = 82
-
Initial target JPEG quality (1-100). ** @return string The generated filename of the stored image.