function ImageStyleDownloadController::sourceImageExists
Same name in other branches
- 9 core/modules/image/src/Controller/ImageStyleDownloadController.php \Drupal\image\Controller\ImageStyleDownloadController::sourceImageExists()
- 10 core/modules/image/src/Controller/ImageStyleDownloadController.php \Drupal\image\Controller\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\ControllerCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.