CoolCMS API

UploaderDropzone extends BaseComponent
in package

Table of Contents

Constants

CLIENT_RESIZE_MAX_DEFAULT  : int = 2560
Browser-side image downscale before upload: a longer side above this limit is redrawn by `dropzone.js` on a canvas to fit it. `0` disables it (attachments must not be modified).
CLIENT_RESIZE_QUALITY_DEFAULT  : float = 0.85
JPEG quality after browser-side downscale (PNG stays PNG and ignores it).
DEFAULT_MAX_PENDING_TOKENS  : int = 20
Default maximum of in-progress upload folders per session (several tabs/forms).
DEFAULT_MAX_SESSION_MB  : int = 300
Default cap, in MB, on the total size of uploaded but not yet submitted files of one session.
SETTING_MAX_PENDING_FORMS  : string = 'upload.dropzone.maxPendingForms'
SETTING_MAX_SESSION_MB  : string = 'upload.dropzone.maxSessionMb'
PENDING_INDEX_KEY  : string = 'pendingTokens'
Session key holding the list of in-progress tokens (oldest first).

Properties

$container  : Container
$routerDispatcher  : RouterDispatcher
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string|null
$allowedExtensions  : array<int, string>
Extensions without a dot, case-insensitive. Empty means MIME check only. A non-empty list is authoritative and the MIME from the upload header is not checked, like the admin {@see \App\UI\Admin\Base\Components\UploaderDropzoneComponent\UploaderDropzone}.
$allowedMimeTypes  : array<string|int, string>
$clientResizeMax  : int
Longer image side after browser-side downscale; `0` means no downscale, see `disableClientResize()`.
$clientResizeQuality  : float
$existingAssets  : array<string|int, mixed>
$fieldName  : string
$hint  : string|null
Hint text under the zone. `null` is the default `dropzone.hint` built from accepted formats and the limit (same configuration as the upload check, see `UploadFormats`), `''` hides it for forms with other limits/types that print their own hint (complaint).
$maxFiles  : int
$maxFileSize  : int
$session  : Session
$sessionSection  : SessionSection
$subDir  : string
$token  : string|null

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
cleanup()  : void
Deletes the temp folder and removes the session record.
configure()  : self
createComponent()  : IComponent|null
disableClientResize()  : self
getAppContext()  : AppContext
getClientResizeMax()  : int
getClientResizeQuality()  : float
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getEffectiveMaxFileSize()  : int
App limit narrowed by the PHP limits (`upload_max_filesize`, `post_max_size`).
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getRouterDispatcher()  : RouterDispatcher
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getTempDir()  : string|null
Returns the temp folder path from the session.
getThemeContext()  : ThemeContext|null
getToken()  : string|null
getUploadedFiles()  : array<int, array{name: string, path: string}>
Returns uploaded files as references `[name, path]`; the content is not read. The Api reads each file itself when it processes it (see {@see \App\Core\Security\Upload\UploadedItem}), so the files never sit in memory together (base64 of all files at once would exceed `memory_limit`).
handleRemove()  : void
AJAX signal: deletes one file from the temp folder.
handleUpload()  : void
AJAX signal: uploads one file. The token comes from the URL (signal parameter) and says which session/folder the file belongs to.
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
injectDeviceDetector()  : void
onCreate()  : void
prepareTempDir()  : string
Prepares the temp folder for uploaded files and returns the token that identifies it.
render()  : void
resolveMaxPendingTokens()  : int
Returns the in-progress forms cap from the setting value; empty, non-numeric or below 1 means the default.
resolveMaxSessionBytes()  : int
Returns the session in-progress files cap in bytes from the setting value in MB; empty, non-numeric or below 1 means the default.
setAppContext()  : $this
setClientResize()  : self
The caller sets browser-side downscale because it knows what the uploader carries.
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setExistingAssets()  : self
Sets existing images (for display in the list).
setHint()  : self
setLanguageContext()  : $this
setLocalizationContext()  : $this
setSettingContext()  : $this
setThemeContext()  : $this
setToken()  : self
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getTranslator()  : ITranslator
setTemplateFile()  : void
setTranslator()  : self
computePendingBytes()  : int
Sums the bytes of files in all in-progress folders of the session.
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
getPendingTokens()  : array<int, string>
getSessionKey()  : string
The session key contains the token, so forms open in parallel (several tabs) have their own record and do not wipe each other's temp folder.
isInsideDropzoneRoot()  : bool
Safety check before deleting: the path must lie under the dropzone root (see `DropzoneTempRoot`).
registerPendingToken()  : void
Registers the session key in the list of in-progress tokens; above `upload.dropzone.maxPendingForms` the oldest is cleaned up (folder and record). The list is shared by all uploaders in the session.
sendJsonResponse()  : void
unregisterPendingToken()  : void

Constants

CLIENT_RESIZE_MAX_DEFAULT

Browser-side image downscale before upload: a longer side above this limit is redrawn by `dropzone.js` on a canvas to fit it. `0` disables it (attachments must not be modified).

public int CLIENT_RESIZE_MAX_DEFAULT = 2560

Server checks (ImageUploadPolicy, Api) do not change; only the transfer and temp shrink.

CLIENT_RESIZE_QUALITY_DEFAULT

JPEG quality after browser-side downscale (PNG stays PNG and ignores it).

public float CLIENT_RESIZE_QUALITY_DEFAULT = 0.85

DEFAULT_MAX_PENDING_TOKENS

Default maximum of in-progress upload folders per session (several tabs/forms).

public int DEFAULT_MAX_PENDING_TOKENS = 20

The setting upload.dropzone.maxPendingForms takes precedence, see resolveMaxPendingTokens().

DEFAULT_MAX_SESSION_MB

Default cap, in MB, on the total size of uploaded but not yet submitted files of one session.

public int DEFAULT_MAX_SESSION_MB = 300

The setting upload.dropzone.maxSessionMb takes precedence, see resolveMaxSessionBytes().

SETTING_MAX_PENDING_FORMS

public string SETTING_MAX_PENDING_FORMS = 'upload.dropzone.maxPendingForms'

SETTING_MAX_SESSION_MB

public string SETTING_MAX_SESSION_MB = 'upload.dropzone.maxSessionMb'

PENDING_INDEX_KEY

Session key holding the list of in-progress tokens (oldest first).

private string PENDING_INDEX_KEY = 'pendingTokens'

Properties

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$translatorDomain

protected string|null $translatorDomain = 'front.base.components.uploaderDropzone'

$allowedExtensions

Extensions without a dot, case-insensitive. Empty means MIME check only. A non-empty list is authoritative and the MIME from the upload header is not checked, like the admin {@see \App\UI\Admin\Base\Components\UploaderDropzoneComponent\UploaderDropzone}.

private array<int, string> $allowedExtensions = []

$allowedMimeTypes

private array<string|int, string> $allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'video/mp4', 'video/quicktime']

$clientResizeMax

Longer image side after browser-side downscale; `0` means no downscale, see `disableClientResize()`.

private int $clientResizeMax = self::CLIENT_RESIZE_MAX_DEFAULT

$clientResizeQuality

private float $clientResizeQuality = self::CLIENT_RESIZE_QUALITY_DEFAULT

$hint

Hint text under the zone. `null` is the default `dropzone.hint` built from accepted formats and the limit (same configuration as the upload check, see `UploadFormats`), `''` hides it for forms with other limits/types that print their own hint (complaint).

private string|null $hint = null

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

__construct()

public __construct(Session $session) : mixed
Parameters
$session : Session

cleanup()

Deletes the temp folder and removes the session record.

public cleanup() : void

Call after a successful save.

configure()

public configure(string $subDir[, int $maxFiles = 10 ][, array<string|int, string> $allowedMimeTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'video/mp4', 'video/quicktime'] ][, int $maxFileSize = 50 * 1024 * 1024 ][, string $fieldName = 'uploaderItems' ][, array<int, string> $allowedExtensions = [] ]) : self
Parameters
$subDir : string
$maxFiles : int = 10
$allowedMimeTypes : array<string|int, string> = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'video/mp4', 'video/quicktime']
$maxFileSize : int = 50 * 1024 * 1024
$fieldName : string = 'uploaderItems'
$allowedExtensions : array<int, string> = []

extensions without a dot, case-insensitive (see the property docblock)

Return values
self

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

disableClientResize()

public disableClientResize() : self
Return values
self

getClientResizeMax()

public getClientResizeMax() : int
Return values
int

getClientResizeQuality()

public getClientResizeQuality() : float
Return values
float

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getEffectiveMaxFileSize()

App limit narrowed by the PHP limits (`upload_max_filesize`, `post_max_size`).

public getEffectiveMaxFileSize() : int
Return values
int

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

getTempDir()

Returns the temp folder path from the session.

public getTempDir() : string|null
Return values
string|null

getUploadedFiles()

Returns uploaded files as references `[name, path]`; the content is not read. The Api reads each file itself when it processes it (see {@see \App\Core\Security\Upload\UploadedItem}), so the files never sit in memory together (base64 of all files at once would exceed `memory_limit`).

public getUploadedFiles() : array<int, array{name: string, path: string}>

Call after a successful form submit. IMPORTANT: the folder must live until the Api call ends; call cleanup() only after saving, otherwise the Api cannot read the files.

Return values
array<int, array{name: string, path: string}>

handleRemove()

AJAX signal: deletes one file from the temp folder.

public handleRemove(string $token) : void
Parameters
$token : string

handleUpload()

AJAX signal: uploads one file. The token comes from the URL (signal parameter) and says which session/folder the file belongs to.

public handleUpload(string $token) : void
Parameters
$token : string

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

prepareTempDir()

Prepares the temp folder for uploaded files and returns the token that identifies it.

public prepareTempDir([bool $forceNew = false ]) : string

The caller must pass the token to the client (hidden form field and signal URL parameter) so later requests hit the right folder. Without a token two parallel form tabs would share one folder and overwrite each other.

The folder is not created on disk, only its path is reserved in the session; it is created physically on the first upload (see handleUpload()). Creating it on every form load left empty folders behind forever. The session also holds at most upload.dropzone.maxPendingForms in-progress tokens; the oldest is cleaned up with its files when the limit is exceeded.

Parameters
$forceNew : bool = false

deletes the old folder and creates a new one (fresh page load)

Return values
string

render()

public render([string $style = 'Style_1' ]) : void
Parameters
$style : string = 'Style_1'

resolveMaxPendingTokens()

Returns the in-progress forms cap from the setting value; empty, non-numeric or below 1 means the default.

public static resolveMaxPendingTokens(mixed $setting) : int
Parameters
$setting : mixed
Return values
int

resolveMaxSessionBytes()

Returns the session in-progress files cap in bytes from the setting value in MB; empty, non-numeric or below 1 means the default.

public static resolveMaxSessionBytes(mixed $setting) : int
Parameters
$setting : mixed
Return values
int

setClientResize()

The caller sets browser-side downscale because it knows what the uploader carries.

public setClientResize(int $maxSide[, float $quality = self::CLIENT_RESIZE_QUALITY_DEFAULT ]) : self

Attachments (PDF, documents, complaint evidence photos) call disableClientResize() because their bytes must not change.

Parameters
$maxSide : int

longer side in px, 0 disables it

$quality : float = self::CLIENT_RESIZE_QUALITY_DEFAULT

JPEG quality 0-1

Return values
self

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

setExistingAssets()

Sets existing images (for display in the list).

public setExistingAssets(array<string|int, mixed> $assets) : self
Parameters
$assets : array<string|int, mixed>

array with keys: imageId, thumbPath, isMain, order

Return values
self

setHint()

public setHint(string|null $hint) : self
Parameters
$hint : string|null
Return values
self

setToken()

public setToken(string|null $token) : self
Parameters
$token : string|null
Return values
self

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

computePendingBytes()

Sums the bytes of files in all in-progress folders of the session.

private computePendingBytes() : int
Return values
int

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

getPendingTokens()

private getPendingTokens() : array<int, string>
Return values
array<int, string>

getSessionKey()

The session key contains the token, so forms open in parallel (several tabs) have their own record and do not wipe each other's temp folder.

private getSessionKey() : string
Return values
string

isInsideDropzoneRoot()

Safety check before deleting: the path must lie under the dropzone root (see `DropzoneTempRoot`).

private isInsideDropzoneRoot(string $dir) : bool
Parameters
$dir : string
Return values
bool

registerPendingToken()

Registers the session key in the list of in-progress tokens; above `upload.dropzone.maxPendingForms` the oldest is cleaned up (folder and record). The list is shared by all uploaders in the session.

private registerPendingToken(string $sessionKey) : void
Parameters
$sessionKey : string

sendJsonResponse()

private sendJsonResponse(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

unregisterPendingToken()

private unregisterPendingToken(string $sessionKey) : void
Parameters
$sessionKey : string
On this page

Search results