isEncrypted() || !$file->getStorage()->isLocal(); } /** * Get a path to either the local file or temporary file * * @param File $file * @param ?int $maxSize maximum size for temporary files */ protected function getLocalFile(File $file, ?int $maxSize = null): string|false { if ($this->useTempFile($file)) { $absPath = Server::get(ITempManager::class)->getTemporaryFile(); if ($absPath === false) { Server::get(LoggerInterface::class)->error( 'Failed to get local file to generate thumbnail for: ' . $file->getPath(), ['app' => 'core'] ); return false; } $content = $file->fopen('r'); if ($content === false) { return false; } if ($maxSize) { $content = stream_get_contents($content, $maxSize); } file_put_contents($absPath, $content); $this->tmpFiles[] = $absPath; return $absPath; } else { $path = $file->getStorage()->getLocalFile($file->getInternalPath()); if (is_string($path)) { return $path; } else { return false; } } } /** * Clean any generated temporary files */ protected function cleanTmpFiles(): void { foreach ($this->tmpFiles as $tmpFile) { unlink($tmpFile); } $this->tmpFiles = []; } }