commit 6151f64752ea172e54c039ceaacb890db4fab0be
parent 5e12c5a28dabb51ff9906ec973680bcf71203d20
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 17 Nov 2015 00:41:21 +0100
Fix for the max upload size
Diffstat:
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/PartKeepr/CoreBundle/Services/SystemService.php b/src/PartKeepr/CoreBundle/Services/SystemService.php
@@ -241,4 +241,24 @@ class SystemService extends ContainerAware
return sprintf('%.1f %sB', $number / pow($unit, $exp), $pre);
}
+
+ /**
+ * Returns the effective size from a human-readable byte format.
+ *
+ * Example:
+ * getBytesFromHumanReadable("1M") will return 1048576.
+ *
+ * @param string $size_str The byte
+ * @return int The bytes
+ */
+ public function getBytesFromHumanReadable ($size_str)
+ {
+ switch (substr ($size_str, -1))
+ {
+ case 'M': case 'm': return (int)$size_str * 1048576;
+ case 'K': case 'k': return (int)$size_str * 1024;
+ case 'G': case 'g': return (int)$size_str * 1073741824;
+ default: return $size_str;
+ }
+ }
}
diff --git a/src/PartKeepr/FrontendBundle/Controller/IndexController.php b/src/PartKeepr/FrontendBundle/Controller/IndexController.php
@@ -24,8 +24,8 @@ class IndexController extends Controller
$aParameters["php_version"] = phpversion();
$aParameters["auto_start_session"] = true;
- $maxPostSize = $this->get("partkeepr_systemservice")->format_bytes(ini_get("post_max_size"));
- $maxFileSize = $this->get("partkeepr_systemservice")->format_bytes(ini_get("upload_max_filesize"));
+ $maxPostSize = $this->get("partkeepr_systemservice")->getBytesFromHumanReadable(ini_get("post_max_size"));
+ $maxFileSize = $this->get("partkeepr_systemservice")->getBytesFromHumanReadable(ini_get("upload_max_filesize"));
$aParameters["maxUploadSize"] = min($maxPostSize, $maxFileSize);