fix: fiabiliser les portées et médias publics
This commit is contained in:
parent
2029849f18
commit
4493357590
11 changed files with 121 additions and 6 deletions
|
|
@ -68,6 +68,7 @@ final class ImageService
|
|||
if (!is_dir($directory) && !mkdir($directory, 0775, true) && !is_dir($directory)) {
|
||||
throw new RuntimeException(t('service.image.directory_failed'));
|
||||
}
|
||||
self::preparePublicDirectory($directory);
|
||||
$prefix = preg_replace('/[^a-z0-9_-]+/i', '_', trim($prefix)) ?: 'photo';
|
||||
$useWebp = $profile !== 'logo';
|
||||
$extension = $useWebp ? 'webp' : $source['extension'];
|
||||
|
|
@ -136,4 +137,25 @@ final class ImageService
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static function preparePublicDirectory(string $directory): void
|
||||
{
|
||||
$mediaRoot = dirname(__DIR__, 2) . '/public/media';
|
||||
$normalized = rtrim(str_replace('\\', '/', $directory), '/');
|
||||
$normalizedRoot = rtrim(str_replace('\\', '/', $mediaRoot), '/');
|
||||
if ($normalized !== $normalizedRoot && !str_starts_with($normalized, $normalizedRoot . '/')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@chmod(dirname(__DIR__, 2) . '/data', 0710);
|
||||
$relative = ltrim(substr($normalized, strlen($normalizedRoot)), '/');
|
||||
$current = $normalizedRoot;
|
||||
@chmod($current, 0755);
|
||||
foreach (array_filter(explode('/', $relative), 'strlen') as $segment) {
|
||||
$current .= '/' . $segment;
|
||||
if (is_dir($current)) {
|
||||
@chmod($current, 0755);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue