Minor changes

This commit is contained in:
julien
2026-03-22 12:49:53 +01:00
parent 24b3bb4177
commit 6481dd0584

View File

@@ -97,12 +97,11 @@ class LocalMediaStorage implements MediaStorageInterface
public function storePreparedUpload(UploadedMediaInterface $uploadedFile, PreparedMediaUpload $preparedUpload): string
{
if (!is_dir($this->uploadDir) && !@mkdir($this->uploadDir, 0755, true)) {
throw new StorageException("Impossible de créer le répertoire d'upload");
}
$this->ensureUploadDirectoryExists();
$filename = uniqid('', true) . '_' . bin2hex(random_bytes(4)) . '.' . $preparedUpload->getExtension();
$destPath = $this->uploadDir . DIRECTORY_SEPARATOR . $filename;
$this->ensureParentDirectoryExists($destPath);
if ($preparedUpload->shouldCopyFromTemporaryPath()) {
if (!copy($preparedUpload->getTemporaryPath(), $destPath)) {
@@ -136,6 +135,22 @@ class LocalMediaStorage implements MediaStorageInterface
}
}
private function ensureUploadDirectoryExists(): void
{
if (!is_dir($this->uploadDir) && !@mkdir($this->uploadDir, 0755, true) && !is_dir($this->uploadDir)) {
throw new StorageException("Impossible de créer le répertoire d'upload");
}
}
private function ensureParentDirectoryExists(string $path): void
{
$directory = dirname($path);
if (!is_dir($directory) && !@mkdir($directory, 0755, true) && !is_dir($directory)) {
throw new StorageException("Impossible de préparer le répertoire cible du média");
}
}
private function assertReasonableDimensions(string $path): void
{
$size = @getimagesize($path);