function FileSystem::saveData
Overrides FileSystemInterface::saveData
File
-
core/
lib/ Drupal/ Core/ File/ FileSystem.php, line 478
Class
- FileSystem
- Provides helpers to operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
public function saveData($data, $destination, $fileExists = FileExists::Rename) {
if (!$fileExists instanceof FileExists) {
// @phpstan-ignore staticMethod.deprecated
$fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
}
// Write the data to a temporary file.
$temp_name = $this->tempnam('temporary://', 'file');
if (file_put_contents($temp_name, $data) === FALSE) {
throw new FileWriteException("Temporary file '{$temp_name}' could not be created.");
}
// Move the file to its final destination.
return $this->move($temp_name, $destination, $fileExists);
}