summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/legal_file.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2012-05-17 20:25:27 -0700
committerBharat Mediratta <bharat@menalto.com>2012-05-17 20:25:27 -0700
commit9e2ea2ffedb22f83137db4e5ba4c06b91f11e09d (patch)
tree2af0965685141af9cabcb01095dc431954de40e2 /modules/gallery/helpers/legal_file.php
parent931da5f2ff68e3e4414583c39a22d62f13f87960 (diff)
Smash multiple extensions down into a single one when accepting file
uploads. Fixes #1872.
Diffstat (limited to 'modules/gallery/helpers/legal_file.php')
-rw-r--r--modules/gallery/helpers/legal_file.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index 075de9cd..bd48d7b7 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -92,4 +92,20 @@ class legal_file_Core {
return preg_replace("/\.[^\.]*?$/", ".{$new_ext}", $filename);
}
}
+
+ /**
+ * Reduce the given file to having a single extension.
+ */
+ static function smash_extensions($filename) {
+ $parts = pathinfo($filename);
+ $result = "";
+ if ($parts["dirname"] != ".") {
+ $result .= $parts["dirname"] . "/";
+ }
+ $parts["filename"] = str_replace(".", "_", $parts["filename"]);
+ $parts["filename"] = preg_replace("/[_]+/", "_", $parts["filename"]);
+ $parts["filename"] = trim($parts["filename"], "_");
+ $result .= "{$parts['filename']}.{$parts['extension']}";
+ return $result;
+ }
}