Skip to content

Commit a002fc3

Browse files
committed
Create destination directory on local disks
1 parent 42e4d6b commit a002fc3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Disk.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function getPath(): string
4343
return $this->disk->getDriver()->getAdapter()->getPathPrefix();
4444
}
4545

46+
public function createDirectory(string $path)
47+
{
48+
return $this->disk->makeDirectory($path);
49+
}
50+
4651
public function __call($method, $parameters)
4752
{
4853
return call_user_func_array([$this->disk, $method], $parameters);

src/MediaExporter.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function save(string $path): Media
5555

5656
$destinationPath = $this->getDestinationPathForSaving($file);
5757

58+
$this->createDestinationPathForSaving($file);
59+
5860
$this->{$this->saveMethod}($destinationPath);
5961

6062
if (!$this->getDisk()->isLocal()) {
@@ -80,6 +82,17 @@ private function getDestinationPathForSaving(File $file): string
8082
return $file->getFullPath();
8183
}
8284

85+
private function createDestinationPathForSaving(File $file)
86+
{
87+
if (!$file->getDisk()->isLocal()) {
88+
return false;
89+
}
90+
91+
$directory = pathinfo($file->getPath())['dirname'];
92+
93+
return $file->getDisk()->createDirectory($directory);
94+
}
95+
8396
private function saveAudioOrVideo(string $fullPath): MediaExporter
8497
{
8598
$this->media->save($this->getFormat(), $fullPath);

0 commit comments

Comments
 (0)