diff --git a/.tests/fixtures/fixture_non_admin.xml b/.tests/fixtures/fixture_non_admin.xml
index 9ace6e0..c4345cd 100644
--- a/.tests/fixtures/fixture_non_admin.xml
+++ b/.tests/fixtures/fixture_non_admin.xml
@@ -22,5 +22,6 @@
+
diff --git a/.tests/tests/MigrateTest.php b/.tests/tests/MigrateTest.php
index 10d52a1..daaa549 100644
--- a/.tests/tests/MigrateTest.php
+++ b/.tests/tests/MigrateTest.php
@@ -80,7 +80,8 @@ class MigrateTest extends UloggerDatabaseTestCase {
["name" => "stroke_color", "value" => "s:7:\"#abcdef\";"],
["name" => "stroke_opacity", "value" => "i:1;"],
["name" => "stroke_weight", "value" => "i:22;"],
- ["name" => "units", "value" => "s:8:\"imperial\";"]
+ ["name" => "units", "value" => "s:8:\"imperial\";"],
+ ["name" => "upload_maxsize", "value" => "i:0;"]
]];
$actual = $this->getConnection()->createQueryTable(
"config",
diff --git a/helpers/config.php b/helpers/config.php
index a76b413..d13c2c8 100644
--- a/helpers/config.php
+++ b/helpers/config.php
@@ -131,8 +131,14 @@ class uConfig {
* @var string Stroke color
*/
public $colorHilite = "#feff6a";
+ /**
+ * @var int Maximum size of uploaded files in bytes.
+ * Will be adjusted to system maximum upload size
+ */
+ public $uploadMaxSize;
public function __construct($useDatabase = true) {
+ $this->uploadMaxSize = uUtils::getUploadMaxSize();
if ($useDatabase) {
$this->setFromDatabase();
}
@@ -215,47 +221,49 @@ class uConfig {
$placeholder = self::db()->lobPlaceholder();
$query = "UPDATE " . self::db()->table('config') . "
SET value = CASE name
- WHEN 'map_api' THEN $placeholder
- WHEN 'latitude' THEN $placeholder
- WHEN 'longitude' THEN $placeholder
- WHEN 'google_key' THEN $placeholder
- WHEN 'require_auth' THEN $placeholder
- WHEN 'public_tracks' THEN $placeholder
- WHEN 'pass_lenmin' THEN $placeholder
- WHEN 'pass_strength' THEN $placeholder
- WHEN 'interval_seconds' THEN $placeholder
- WHEN 'lang' THEN $placeholder
- WHEN 'units' THEN $placeholder
- WHEN 'stroke_weight' THEN $placeholder
- WHEN 'stroke_color' THEN $placeholder
- WHEN 'stroke_opacity' THEN $placeholder
+ WHEN 'color_extra' THEN $placeholder
+ WHEN 'color_hilite' THEN $placeholder
WHEN 'color_normal' THEN $placeholder
WHEN 'color_start' THEN $placeholder
WHEN 'color_stop' THEN $placeholder
- WHEN 'color_extra' THEN $placeholder
- WHEN 'color_hilite' THEN $placeholder
+ WHEN 'google_key' THEN $placeholder
+ WHEN 'interval_seconds' THEN $placeholder
+ WHEN 'lang' THEN $placeholder
+ WHEN 'latitude' THEN $placeholder
+ WHEN 'longitude' THEN $placeholder
+ WHEN 'map_api' THEN $placeholder
+ WHEN 'pass_lenmin' THEN $placeholder
+ WHEN 'pass_strength' THEN $placeholder
+ WHEN 'public_tracks' THEN $placeholder
+ WHEN 'require_auth' THEN $placeholder
+ WHEN 'stroke_color' THEN $placeholder
+ WHEN 'stroke_opacity' THEN $placeholder
+ WHEN 'stroke_weight' THEN $placeholder
+ WHEN 'units' THEN $placeholder
+ WHEN 'upload_maxsize' THEN $placeholder
END";
$stmt = self::db()->prepare($query);
$params = [
- $this->mapApi,
- $this->initLatitude,
- $this->initLongitude,
- $this->googleKey,
- $this->requireAuthentication,
- $this->publicTracks,
- $this->passLenMin,
- $this->passStrength,
- $this->interval,
- $this->lang,
- $this->units,
- $this->strokeWeight,
- $this->strokeColor,
- $this->strokeOpacity,
+ $this->colorExtra,
+ $this->colorHilite,
$this->colorNormal,
$this->colorStart,
$this->colorStop,
- $this->colorExtra,
- $this->colorHilite
+ $this->googleKey,
+ $this->initLatitude,
+ $this->initLongitude,
+ $this->interval,
+ $this->lang,
+ $this->mapApi,
+ $this->passLenMin,
+ $this->passStrength,
+ $this->publicTracks,
+ $this->requireAuthentication,
+ $this->strokeColor,
+ $this->strokeOpacity,
+ $this->strokeWeight,
+ $this->units,
+ $this->uploadMaxSize
];
$stmt->execute(array_map('serialize', $params));
@@ -419,6 +427,12 @@ class uConfig {
if (isset($arr['color_hilite']) && !empty($arr['color_hilite'])) {
$this->colorHilite = $arr['color_hilite'];
}
+ if (isset($arr['upload_maxsize']) && is_numeric($arr['upload_maxsize'])) {
+ $this->uploadMaxSize = (int) $arr['upload_maxsize'];
+ if ($this->uploadMaxSize === 0 || $this->uploadMaxSize > uUtils::getUploadMaxSize()) {
+ $this->uploadMaxSize = uUtils::getUploadMaxSize();
+ }
+ }
}
}
diff --git a/helpers/upload.php b/helpers/upload.php
index 15a4380..2fdfbf0 100644
--- a/helpers/upload.php
+++ b/helpers/upload.php
@@ -32,7 +32,7 @@ class uUpload {
const META_ERROR = "error";
const META_SIZE = "size";
public static $uploadDir = ROOT_DIR . "/uploads/";
- private static $filePattern = "[a-z0-9_.]{20,}";
+ private static $filePattern = "/[a-z0-9_.]{20,}/";
private static $mimeMap = [];
/**
diff --git a/index.php b/index.php
index bf1217e..6812991 100644
--- a/index.php
+++ b/index.php
@@ -125,7 +125,7 @@
diff --git a/js/src/ajax.js b/js/src/ajax.js
index ce5bd4b..9551ca9 100644
--- a/js/src/ajax.js
+++ b/js/src/ajax.js
@@ -42,7 +42,7 @@ export default class uAjax {
/**
* Perform ajax HTTP request
* @param {string} url Request URL
- * @param {Object|HTMLFormElement} [data] Optional request parameters: key/value pairs or form element
+ * @param {Object|HTMLFormElement|FormData} [data] Optional request parameters: key/value pairs or form element
* @param {Object} [options] Optional options
* @param {string} [options.method='GET'] Optional query method, default 'GET'
* @return {Promise