FileSaver
API reference › FilePond › file › FileSaver
Writes encoded FilePond uploads to a directory with sanitized file names.
Methods
Section titled “Methods”| Method | Description | Defined 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(string $directory, int $directoryMode = 0775, int $fileMode = 0644)Parameters
| Parameter | Type | Description |
|---|---|---|
$directory | string | Target directory, optionally as a registered Yii alias; created when missing. |
$directoryMode | int | Permissions applied to directories created by the saver. |
$fileMode | int | Permissions applied to written files. |
save()
Section titled “save() ”public function save(yii2\extensions\filepond\file\EncodedFile $file, string|null $name = null): stringWrites 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
| Parameter | Type | Description |
|---|---|---|
$file | EncodedFile | File to write. |
$name | string| | Base 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.
saveAll()
Section titled “saveAll() ”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
| Parameter | Type | Description |
|---|---|---|
$files | iterable<EncodedFile> | Files to write. |
$name | string| | Base 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.