Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ImageStyleDownloadController.php

function ImageStyleDownloadController::sourceImageExists

Checks whether the provided source image exists.

Parameters

string $image_uri: The URI for the source image.

bool $token_is_valid: Whether a valid image token was supplied.

Return value

bool Whether the source image exists.

1 call to ImageStyleDownloadController::sourceImageExists()
ImageStyleDownloadController::deliver in core/modules/image/src/Controller/ImageStyleDownloadController.php
Generates a derivative, given a style and image path.

File

core/modules/image/src/Controller/ImageStyleDownloadController.php, line 260

Class

ImageStyleDownloadController
Defines a controller to serve image styles.

Namespace

Drupal\image\Controller

Code

private function sourceImageExists(string $image_uri, bool $token_is_valid) : bool {
    $exists = file_exists($image_uri);
    // If the file doesn't exist, we can stop here.
    if (!$exists) {
        return FALSE;
    }
    if ($token_is_valid) {
        return TRUE;
    }
    if (StreamWrapperManager::getScheme($image_uri) !== 'public') {
        return TRUE;
    }
    $image_path = $this->fileSystem
        ->realpath($image_uri);
    $private_path = Settings::get('file_private_path');
    if ($private_path) {
        $private_path = realpath($private_path);
        if ($private_path && str_starts_with($image_path, $private_path)) {
            return FALSE;
        }
    }
    return TRUE;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal