Skip to content
PHP Ecosystem
Explore

FileSaver

API reference › FilePond › file › FileSaver

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

Writes encoded FilePond uploads to a directory with sanitized file names.

MethodDescriptionDefined by
__construct()FileSaver
save()Writes the file and returns its absolute path, replacing a file with the same name.FileSaver
saveAll()Writes every file and returns their absolute paths.FileSaver
public function __construct(string $directory, int $directoryMode = 0775, int $fileMode = 0644)

Parameters

ParameterTypeDescription
$directorystringTarget directory, optionally as a registered Yii alias; created when missing.
$directoryModeintPermissions applied to directories created by the saver.
$fileModeintPermissions applied to written files.
public function save(yii2\extensions\filepond\file\EncodedFile $file, string|null $name = null): string

Writes the file and returns its absolute path, replacing a file with the same name.

The extension follows the MIME type detected from the content: the client extension is kept only when it is registered for that type, so a polyglot such as avatar.php holding GIF data is stored as .gif. The base name is sanitized to [A-Za-z0-9_-], so passing $name is the reliable way to control the stored file name.

Parameters

ParameterTypeDescription
$fileEncodedFileFile to write.
$namestring|nullBase name without extension, or null to derive it from the client file name.

Returns

string: Absolute path of the written file.

Throws

  • RuntimeException: if the directory is not writable or the file cannot be written.
public function saveAll(iterable<yii2\extensions\filepond\file\EncodedFile> $files, string|null $name = null): list<string>

Writes every file and returns their absolute paths.

When $name is given, the first file keeps it and the following ones receive a numeric suffix. Files that would share a path within the batch, such as two uploads with the same client name, receive a -1, -2, … suffix instead of overwriting each other.

Parameters

ParameterTypeDescription
$filesiterable<EncodedFile>Files to write.
$namestring|nullBase name without extension, or null to derive it from each client file name.

Returns

list<string>: Absolute paths of the written files.

Throws

  • RuntimeException: if the directory is not writable or a file cannot be written.