Skip to content

Commit

Permalink
image helper should automatically create destination directory if nee…
Browse files Browse the repository at this point in the history
…ded and possible
  • Loading branch information
brookgagnon committed Sep 7, 2024
1 parent 84fbcfd commit 33ce20a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion classes/core/obfhelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,24 @@ public static function image_resize($src, $dst, $width, $height)
trigger_error('The source file does not exist', E_USER_WARNING);
return false;
}
if (!is_writeable(pathinfo($dst)['dirname'])) {

// get destination directory and create if it doesn't exist
$dst_pathinfo = pathinfo($dst);
if (!is_dir($dst_pathinfo['dirname'])) {
mkdir($dst_pathinfo['dirname'], 0777, true);
echo $dst_pathinfo['dirname'];
}

// make sure it exists now
if (!is_dir($dst_pathinfo['dirname'])) {
echo 'foo';
trigger_error('Unable to create destination directory.', E_USER_WARNING);
return false;
}

// and we can write to it
if (!is_writeable($dst_pathinfo['dirname'])) {
echo 'bar';
trigger_error('The destination directory is not writeable', E_USER_WARNING);
return false;
}
Expand Down

0 comments on commit 33ce20a

Please sign in to comment.