diff --git a/core/util.php b/core/util.php index 63e4f725..63cdac07 100644 --- a/core/util.php +++ b/core/util.php @@ -281,14 +281,20 @@ function manual_include(string $fname): ?string function path_to_tags(string $path): string { $matches = []; - if (preg_match("/\d+ - (.*)\.([a-zA-Z]+)/", basename($path), $matches)) { + $tags = ""; + if(preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) { $tags = $matches[1]; - } else { - $tags = dirname($path); - $tags = str_replace("/", " ", $tags); - $tags = str_replace("__", " ", $tags); - $tags = trim($tags); - } + } + + $dir_tags = dirname($path); + $dir_tags = str_replace("/", " ", $dir_tags); + $dir_tags = str_replace("__", " ", $dir_tags); + $dir_tags = trim($dir_tags); + if ($dir_tags != "") { + $tags = trim($tags)." ".trim($dir_tags); + } + $tags = trim ( $tags ); + return $tags; } diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index 5f67f909..6168e776 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -273,6 +273,11 @@ class CronUploader extends Extension $this->move_uploaded($img[0], $img[1], false); } catch (Exception $e) { $this->move_uploaded($img[0], $img[1], true); + if (strpos($e->getMessage(), 'SQLSTATE') !== false) { + // Postgres invalidates the transaction if there is an SQL error, + // so all subsequence transactions will fail. + break; + } } } @@ -289,16 +294,23 @@ class CronUploader extends Extension // Create $newDir = $this->root_dir; - // Determine which dir to move to - if ($corrupt) { - // Move to corrupt dir - $newDir .= "/failed_to_upload/"; - $info = "ERROR: Image was not uploaded."; - } else { - $newDir .= "/uploaded/"; - $info = "Image successfully uploaded. "; - } - + $relativeDir = dirname(substr($path, strlen($this->root_dir) + 7)); + + // Determine which dir to move to + if ($corrupt) { + // Move to corrupt dir + $newDir .= "/failed_to_upload/".$relativeDir; + $info = "ERROR: Image was not uploaded."; + } + else { + $newDir .= "/uploaded/".$relativeDir; + $info = "Image successfully uploaded. "; + } + $newDir = str_replace ( "//", "/", $newDir."/" ); + + if (!is_dir($newDir)) + mkdir ( $newDir, 0775, true ); + // move file to correct dir rename($path, $newDir.$filename);