Documentation

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

$allowedFileTypes

private array<string|int, mixed> $allowedFileTypes = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'xlsx', 'docx', 'pdf']

Methods

hasPostedFiles()

public hasPostedFiles(string $key) : bool
Parameters
$key : string
Return values
bool

setAllowedFileTypes()

Sets allowed file types

public setAllowedFileTypes(array<string|int, mixed> $fileTypes) : $this
Parameters
$fileTypes : array<string|int, mixed>
Return values
$this

setFileNamePrefix()

Sets prefix to be prepended to the file name

public setFileNamePrefix(string $prefix) : $this
Parameters
$prefix : string
Return values
$this

setImageOptimization()

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
$this

setUploadDir()

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
$this

upload()

Uploads the posted files

public upload(string $key) : array<string|int, mixed>
Parameters
$key : string
  • form input name
Tags
throws
Throwable
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
Tags
throws
Throwable
Return values
string

        
On this page

Search results