Skip to content
PHP Ecosystem
Explore

EncodedFile

API reference › FilePond › file › EncodedFile

final readonly classyii2\extensions\filepond\file\EncodedFile
Sourcesrc/file/EncodedFile.php

Represents a file submitted by the FilePond File Encode plugin as a base64 JSON payload.

See also: https://pqina.nl/filepond/docs/api/plugins/file-encode/.

PropertyTypeDescriptionDefined by
$metadata readonly constructorarray<string, mixed>FilePond item metadata, such as crop or poster.EncodedFile
$name readonly constructorstringClient file name.EncodedFile
$type readonly constructorstringClient MIME type as reported by the browser.EncodedFile
MethodDescriptionDefined by
fromArray() staticCreates a file from a decoded File Encode payload.EncodedFile
fromInput() staticCreates the files submitted by one FilePond input.EncodedFile
fromJson() staticCreates a file from the JSON string submitted by the File Encode plugin.EncodedFile
getCropRectangle()Returns the crop rectangle in source image pixels stored by the Cropper.js editor.EncodedFile
getData()Returns the decoded binary content.EncodedFile
getExtension()Returns the lowercase extension of the client file name.EncodedFile
getMimeType()Returns the MIME type detected from the content rather than the client-reported $type.EncodedFile
getSize()Returns the content size in bytes.EncodedFile
withData()Returns a copy with different content, for example after server-side processing.EncodedFile
public static function fromArray(array<array-key, mixed> $payload): self

Creates a file from a decoded File Encode payload.

Parameters

ParameterTypeDescription
$payloadarray<array-key, mixed>Payload with name and base64 data, plus optional type and metadata.

Returns

self: File with decoded content.

Throws

public static function fromInput(mixed $input): list<self>

Creates the files submitted by one FilePond input.

Accepts the raw request value: a JSON string for single inputs, a list of JSON strings or decoded payloads for multiple inputs, and null or empty values when nothing was selected.

Parameters

ParameterTypeDescription
$inputmixedRequest value of the FilePond input.

Returns

list<self>: Decoded files, empty when nothing was submitted.

Throws

public static function fromJson(string $json): self

Creates a file from the JSON string submitted by the File Encode plugin.

Parameters

ParameterTypeDescription
$jsonstringJSON object with name, type, data, and optional metadata.

Returns

self: File with decoded content.

Throws

public function getCropRectangle(): array{x: int, y: int, width: int, height: int}|null

Returns the crop rectangle in source image pixels stored by the Cropper.js editor.

Returns

array{x: int, y: int, width: int, height: int}|null: Rectangle, or null when the file was not cropped.

public function getData(): string

Returns the decoded binary content.

Returns

string: File content.

public function getExtension(): string

Returns the lowercase extension of the client file name.

Returns

string: Extension without the dot, or an empty string.

public function getMimeType(): string

Returns the MIME type detected from the content rather than the client-reported $type.

Returns

string: Detected MIME type, or application/octet-stream when detection fails.

public function getSize(): int

Returns the content size in bytes.

Returns

int: Size in bytes.

public function withData(string $data, string|null $type = null, string|null $name = null): self

Returns a copy with different content, for example after server-side processing.

Parameters

ParameterTypeDescription
$datastringNew binary content.
$typestring|nullNew client MIME type, or null to keep the current one.
$namestring|nullNew client file name, or null to keep the current one.

Returns

self: Copy with the replaced values.