FileUploader
in package
Table of Contents
Constants
- SUPPORTED_IMAGE_TYPES = ['jpg', 'jpeg', 'png', 'gif']
Properties
- $image : Image
- $allowedFileTypes : array<string|int, mixed>
- $fileNamePrefix : string
- $filesPerDir : int
- $fs : Filesystem
- $maxHeight : int|null
- $maxWidth : int|null
- $optimizeImages : bool
- $request : Request
- $uploadDir : string
- $useSubDirs : bool
Methods
- __construct() : mixed
- hasPostedFiles() : bool
- setAllowedFileTypes() : $this
- Sets allowed file types
- setFileNamePrefix() : $this
- Sets prefix to be prepended to the file name
- setImageOptimization() : $this
- Sets optimization for images
- setUploadDir() : $this
- Sets upload directory, whether to use sub-directories and max files per sub-directory
- upload() : array<string|int, mixed>
- Uploads the posted files
- getUploadsSubDir() : string
- Returns the sub-directory where the file shall be uploaded
Constants
SUPPORTED_IMAGE_TYPES
public
mixed
SUPPORTED_IMAGE_TYPES
= ['jpg', 'jpeg', 'png', 'gif']
Properties
$image
protected
Image
$image
$allowedFileTypes
private
array<string|int, mixed>
$allowedFileTypes
= ['jpg', 'jpeg', 'png', 'gif', 'webp', 'xlsx', 'docx', 'pdf']
$fileNamePrefix
private
string
$fileNamePrefix
= ""
$filesPerDir
private
int
$filesPerDir
= 5000
$fs
private
Filesystem
$fs
$maxHeight
private
int|null
$maxHeight
$maxWidth
private
int|null
$maxWidth
$optimizeImages
private
bool
$optimizeImages
= false
$request
private
Request
$request
$uploadDir
private
string
$uploadDir
= ''
$useSubDirs
private
bool
$useSubDirs
= true
Methods
__construct()
public
__construct(Request $request, Filesystem $fs) : mixed
Parameters
- $request : Request
- $fs : Filesystem
hasPostedFiles()
public
hasPostedFiles(string $key) : bool
Parameters
- $key : string
Return values
boolsetAllowedFileTypes()
Sets allowed file types
public
setAllowedFileTypes(array<string|int, mixed> $fileTypes) : $this
Parameters
- $fileTypes : array<string|int, mixed>
Return values
$thissetFileNamePrefix()
Sets prefix to be prepended to the file name
public
setFileNamePrefix(string $prefix) : $this
Parameters
- $prefix : string
Return values
$thissetImageOptimization()
Sets optimization for images
public
setImageOptimization(array<string|int, mixed> $imageSettings) : $this
Parameters
- $imageSettings : array<string|int, mixed>
-
['optimize'] - whether to optimize images or not ['maxWidth'] - max width ['maxHeight'] - max height
Return values
$thissetUploadDir()
Sets upload directory, whether to use sub-directories and max files per sub-directory
public
setUploadDir(string $uploadDir[, bool $useSubDirs = true ][, int $filesPerDir = 5000 ]) : $this
Parameters
- $uploadDir : string
- $useSubDirs : bool = true
- $filesPerDir : int = 5000
Return values
$thisupload()
Uploads the posted files
public
upload(string $key) : array<string|int, mixed>
Parameters
- $key : string
-
- form input name
Tags
Return values
array<string|int, mixed>getUploadsSubDir()
Returns the sub-directory where the file shall be uploaded
private
getUploadsSubDir(string $baseDir, int $filesPerDir) : string
Find subdir with biggest "$dirNum". If it has more files that $filesPerDir, create a new sub-directory
Parameters
- $baseDir : string
- $filesPerDir : int