Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6481dd0584 |
@@ -97,12 +97,11 @@ class LocalMediaStorage implements MediaStorageInterface
|
|||||||
|
|
||||||
public function storePreparedUpload(UploadedMediaInterface $uploadedFile, PreparedMediaUpload $preparedUpload): string
|
public function storePreparedUpload(UploadedMediaInterface $uploadedFile, PreparedMediaUpload $preparedUpload): string
|
||||||
{
|
{
|
||||||
if (!is_dir($this->uploadDir) && !@mkdir($this->uploadDir, 0755, true)) {
|
$this->ensureUploadDirectoryExists();
|
||||||
throw new StorageException("Impossible de créer le répertoire d'upload");
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = uniqid('', true) . '_' . bin2hex(random_bytes(4)) . '.' . $preparedUpload->getExtension();
|
$filename = uniqid('', true) . '_' . bin2hex(random_bytes(4)) . '.' . $preparedUpload->getExtension();
|
||||||
$destPath = $this->uploadDir . DIRECTORY_SEPARATOR . $filename;
|
$destPath = $this->uploadDir . DIRECTORY_SEPARATOR . $filename;
|
||||||
|
$this->ensureParentDirectoryExists($destPath);
|
||||||
|
|
||||||
if ($preparedUpload->shouldCopyFromTemporaryPath()) {
|
if ($preparedUpload->shouldCopyFromTemporaryPath()) {
|
||||||
if (!copy($preparedUpload->getTemporaryPath(), $destPath)) {
|
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
|
private function assertReasonableDimensions(string $path): void
|
||||||
{
|
{
|
||||||
$size = @getimagesize($path);
|
$size = @getimagesize($path);
|
||||||
|
|||||||
Reference in New Issue
Block a user