From b58b4b0e430c46f4776426a5acb33e9d98929300 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 23 Dec 2023 10:28:49 +0100 Subject: [PATCH] Add more detailed exception messages for NotWritableException --- src/File.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/File.php b/src/File.php index 892865ce..964d6cee 100644 --- a/src/File.php +++ b/src/File.php @@ -28,6 +28,21 @@ class File implements FileInterface */ public function save(string $filepath): void { + $dir = pathinfo($filepath, PATHINFO_DIRNAME); + + if (!is_dir($dir)) { + throw new NotWritableException( + "Can't write image to path. Directory does not exist." + ); + } + + if (!is_writable($dir)) { + throw new NotWritableException( + "Can't write image to path. Directory is not writable." + ); + } + + // write date $saved = @file_put_contents($filepath, (string) $this); if ($saved === false) { throw new NotWritableException(