12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace OC\Files\Storage;
- trait LocalTempFileTrait {
-
- protected array $cachedFiles = [];
- protected function getCachedFile(string $path): string|false {
- if (!isset($this->cachedFiles[$path])) {
- $this->cachedFiles[$path] = $this->toTmpFile($path);
- }
- return $this->cachedFiles[$path];
- }
-
- protected function removeCachedFile($path) {
- unset($this->cachedFiles[$path]);
- }
- protected function toTmpFile(string $path): string|false {
- $source = $this->fopen($path, 'r');
- if (!$source) {
- return false;
- }
- if ($pos = strrpos($path, '.')) {
- $extension = substr($path, $pos);
- } else {
- $extension = '';
- }
- $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension);
- $target = fopen($tmpFile, 'w');
- \OC_Helper::streamCopy($source, $target);
- fclose($target);
- return $tmpFile;
- }
- }
|