1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?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;
- }
- }
|