Skip to content
Viames Marino edited this page Feb 23, 2026 · 1 revision

Pair framework: Upload

Pair\Helpers\Upload manages uploaded files from form fields.

It validates upload status and provides local or S3 save helpers.

Constructor

__construct(string $fieldName)

Initializes upload object from $_FILES[$fieldName].

Main methods

save(string $path, ?string $name = null, bool $random = false): bool

Saves file locally.

saveS3(string $filePath, AmazonS3 $amazonS3): void

Uploads file using provided AmazonS3 service.

getLastError(): ?string

Returns last upload-related error.

Implementation example

use Pair\Helpers\Upload;

$upload = new Upload('avatar');

if (!$upload->save(APPLICATION_PATH . '/public/uploads', null, true)) {
    throw new \Exception($upload->getLastError() ?? 'Upload failed');
}

S3 example:

$upload->saveS3('avatars/user-42.jpg', $amazonS3);

See also: AmazonS3, Utilities, Form.

Clone this wiki locally