Skip to content

Commit

Permalink
Create directory if not exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
ABGEO committed Aug 30, 2019
1 parent 975f014 commit 22fe69c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@
);

// Export document to file.
$document->export2File(__DIR__ . '/example.MD');
$document->export2File(__DIR__ . '/generated/example.MD');
File renamed without changes.
5 changes: 5 additions & 0 deletions src/MDGenerator/ExporterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function export2File(string $path): void
$content = $this->_documentContent;

try {
$directory = dirname($path);
if (!file_exists($directory)) {
mkdir($directory, 0755, true);
}

file_put_contents($path, $content);
}
catch (Exception $e) {
Expand Down

0 comments on commit 22fe69c

Please sign in to comment.