AssetTrait
Table of Contents
Methods
- deleteAsset() : void
- Deletes an asset file by its absolute path.
- saveAsset() : string|null
- Saves one base64 image; `null` means the image did not pass {@see ImageUploadPolicy}.
- saveAssets() : array<int, string>
- Saves base64 images into a directory, raster images only, per {@see ImageUploadPolicy}.
Methods
deleteAsset()
Deletes an asset file by its absolute path.
protected
deleteAsset(string|null $absolutePath) : void
Parameters
- $absolutePath : string|null
-
Full absolute path to the file
saveAsset()
Saves one base64 image; `null` means the image did not pass {@see ImageUploadPolicy}.
protected
saveAsset(array<string|int, mixed> $asset, string $dir) : string|null
Parameters
- $asset : array<string|int, mixed>
-
['name' => 'filename.jpg', 'data' => 'base64...']
- $dir : string
-
Absolute path to target directory
Return values
string|nullsaveAssets()
Saves base64 images into a directory, raster images only, per {@see ImageUploadPolicy}.
protected
saveAssets(array<string|int, mixed> $assets, string $dir) : array<int, string>
IMPORTANT: the type is detected from the content, a decompression bomb is rejected by its header and
the image is re-saved through GD (orientation applied, metadata stripped). Writing raw bytes with the
extension from the name would let a new internal caller store an svg with a script and keep EXIF
(including GPS) in every photo. A rejected file is skipped (written to the assets log).
Parameters
- $assets : array<string|int, mixed>
-
[['name' => 'filename.jpg', 'data' => 'base64...'], ...] (from the Api meta; the shape is verified here)
- $dir : string
-
Absolute path to target directory
Return values
array<int, string> —saved file names (without the rejected ones)