- file_put_contents($filepath, $image->asString());
- chmod($filepath, $file_perm);
- chgrp($filepath, $group);
+ if (!file_put_contents($filepath, $image->asString())) {
+ Logger::warning('File could not be created', ['file' => $filepath]);
+ }
+
+ $old_perm = fileperms($filepath) & 0666;
+ $old_group = filegroup($filepath);
+
+ if (($old_perm != $file_perm) && !chmod($filepath, $file_perm)) {
+ Logger::notice('File permissions could not be changed', ['file' => $filepath, 'old' => $old_perm, 'new' => $file_perm]);
+ }
+
+ if (($old_group != $group) && !chgrp($filepath, $group)) {
+ Logger::notice('File group could not be changed', ['file' => $filepath, 'old' => $old_group, 'new' => $group]);
+ }