public function FileHelper::updateSize in SVG Upload Sanitizer 8
Try to update the saved size of a file.
Parameters
\Drupal\file\FileInterface $file: The file.
Return value
bool TRUE if the size was successfully updated, FALSE otherwise.
File
- src/
Helper/ FileHelper.php, line 47
Class
- FileHelper
- File helper class.
Namespace
Drupal\svg_upload_sanitizer\HelperCode
public function updateSize(FileInterface $file) {
$file_path = $this->fileSystem
->realpath($file
->getFileUri());
if (FALSE === $file_path) {
$this->logger
->error(sprintf('Could not resolve the path of the file (URI: "%s").', $file
->getFileUri()));
return FALSE;
}
$size = @filesize($file_path);
if (FALSE === $size) {
$this->logger
->error(sprintf('Could not get the file size (path: "%s").', $file_path));
return FALSE;
}
$file
->setSize($size);
try {
$file
->save();
} catch (EntityStorageException $e) {
$this->logger
->error(sprintf('Could not save the file (fid: "%s", path: "%s").', $file
->id(), $file_path));
}
return TRUE;
}