Classi per la configurazione upload
Cristiano Magro
2018-01-16 371ed41c336704699febc7ad2c30e1d4886bf1c0
src/UploadFile/SetupUpload.class.php
@@ -131,7 +131,7 @@
     */
    public function setNumMaxFiles($numero) {
        if (!is_integer($numero) || $numero <= 0) {
            throw new UploadFile_Exc();
            throw new Upload_Exc_Error();
        }
        $this->numMaxFiles = $numero;
@@ -200,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));