From e3143d210800f4e51f6fb6da83881139d04f01d7 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Tue, 16 Jan 2018 15:49:40 +0100
Subject: [PATCH] Refactor correggo i nomi delle classi e le imposto nel autoloader
---
src/UploadFile/SetupUpload.class.php | 44 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/src/UploadFile/SetupUpload.class.php b/src/UploadFile/SetupUpload.class.php
index e21e31d..a143a0c 100644
--- a/src/UploadFile/SetupUpload.class.php
+++ b/src/UploadFile/SetupUpload.class.php
@@ -56,8 +56,16 @@
return $this->sizeLimitFileUpload;
}
+ /**
+ * Dimensione massima del singolo file caricato
+ *
+ * Accetta sia '1024' che '1 kb' effettuando la conversione interna
+ * necessaria.
+ * @param string $x sia '1024' che '1 kb'
+ * @return \SetupUpload
+ */
public function setSizeLimitFile($x) {
- $this->sizeLimitFileUpload = $x;
+ $this->sizeLimitFileUpload = self::str2Bytes($x);
return $this;
}
@@ -122,10 +130,10 @@
* @return \SetupUpload fluent style
*/
public function setNumMaxFiles($numero) {
- if(!is_integer($numero) || $numero <= 0){
+ if (!is_integer($numero) || $numero <= 0) {
throw new UploadFile_Exc();
- }
-
+ }
+
$this->numMaxFiles = $numero;
return $this;
}
@@ -134,8 +142,16 @@
return $this->sizeMaxFilesByte;
}
+ /**
+ * Dimensione Totale massima dei file caricabili
+ *
+ * Accetta sia '1024' che '1 kb' effettuando la conversione interna
+ * necessaria.
+ * @param string $x sia '1024' che '1 kb'
+ * @return \SetupUpload
+ */
public function setSizeMaxFilesByte($x) {
- $this->sizeMaxFilesByte = $x;
+ $this->sizeMaxFilesByte = self::str2Bytes($x);
return $this;
}
@@ -184,15 +200,29 @@
* 1 Mb = 1024^2
*
* @param string $strSize Stringa da convertire
+ * @throws UploadFile_Excs
* @return integer
*/
public static function str2Bytes($strSize) {
+ $Units = array('b' => 0, 'kb' => 1, 'mb' => 2, 'gb' => 3, 'tb' => 4);
+
$strUnit = strtolower($strSize);
$strUnit = preg_replace('/[^a-z]/', '', $strUnit);
+ $strValue = preg_replace('/[^0-9]/', '', $strSize);
+ $value = intval($strValue);
- $value = intval(preg_replace('/[^0-9]/', '', $strSize));
+ //validazione
+ if (strlen(trim($strSize)) === 0) {
+ //una stringa vuota non può essere convertita
+ throw new Upload_Exc_Error();
+ } elseif (strlen(trim($strValue)) === 0) {
+ //se non trovo la parte del valore della stringa non posso convertire
+ throw new Upload_Exc_Error();
+ } elseif (strlen($strUnit) >= 1 && !array_key_exists($strUnit, $Units)) {
+ //l'unita' non e' nota
+ throw new Upload_Exc_Error();
+ }
- $Units = array('b' => 0, 'kb' => 1, 'mb' => 2, 'gb' => 3, 'tb' => 4);
$Exponent = isset($Units[$strUnit]) ? $Units[$strUnit] : 0;
return ($value * pow(1024, $Exponent));
--
Gitblit v1.8.0