public static function base64ImageUpload($inputName, $path, $encryption = false, $newFilename = false)
    {
        $json	    = json_decode(Request::input($inputName));
        $imageData 	= base64_decode(explode(',', $json->data)[1]);
        $nameArray  = explode('.', $json->name);

        $extension	= strtolower($nameArray[1]);
        $basename	= strtolower($nameArray[0]);

        if ($encryption)
        {
            mt_srand();
            $filename = md5(uniqid(mt_rand())) . "." . $extension;
        }
        elseif ($newFilename)
        {
            $filename = $newFilename . "." . $extension;
        }
        else
        {
            $filename = $json->name;
        }

        $i = 0;
        while(file_exists($path . '/' . $filename))
        {
            $i++;
            $filename = $basename . '-' . $i . '.' . $extension;
        }

        $handle	= fopen($path . '/' . $filename, 'w');
        fwrite($handle, $imageData);
        fclose($handle);

        return $filename;
    }