Skip to content

Commit

Permalink
introduce constant TEMP_FILE_PREFIX
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdruid committed Feb 18, 2025
1 parent 16006f5 commit 76a7dc0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/InterventionBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class InterventionBackend implements Image_Backend, Flushable
*/
const CACHE_DIMENSIONS = 'DIMENSIONS_';

/**
* Prefix for temp file names
*/
private const TEMP_FILE_PREFIX = 'interventionimage_';

/**
* Is cache flushing enabled?
*
Expand Down Expand Up @@ -258,7 +263,7 @@ public function getImageResource()
// write the file to a local path so we can extract exif data if it exists.
// Currently exif data can only be read from file paths and not streams
$tempPath = $this->config()->get('local_temp_path') ?? TEMP_PATH;
$path = tempnam($tempPath ?? '', 'interventionimage_');
$path = tempnam($tempPath ?? '', TEMP_FILE_PREFIX);
if ($extension = pathinfo($assetContainer->getFilename() ?? '', PATHINFO_EXTENSION)) {
//tmpnam creates a file, we should clean it up if we are changing the path name
unlink($path ?? '');
Expand Down Expand Up @@ -815,7 +820,7 @@ public function __destruct()
$this->image->destroy();
}
// remove our temp file if it exists
if (str_starts_with(basename($this->getTempPath()), 'interventionimage_') && file_exists($this->getTempPath() ?? '')) {
if (str_starts_with(basename($this->getTempPath()), TEMP_FILE_PREFIX) && file_exists($this->getTempPath() ?? '')) {
unlink($this->getTempPath() ?? '');
}
}
Expand Down

0 comments on commit 76a7dc0

Please sign in to comment.