保存上传的图片
@param $name
@param null $filename
@param null $allow
@return bool
346599
function save($name, $filename = null, $allow = null)
    {
        //检查请求中是否存在上传的文件
        if (empty($_FILES[$name]['type']))
        {
            $this->error_msg = "No upload file '$name'!";
            $this->error_code = 0;
            return false;
        }

        //文件存储的路径
        $base_dir = empty($this->sub_dir) ? $this->base_dir : $this->base_dir . $this->sub_dir . '/';

        //切分目录
        if ($this->shard_type == 'randomkey')
        {
            if (empty($this->shard_argv))
            {
                $this->shard_argv = 8;
            }
            $sub_dir = RandomKey::randmd5($this->shard_argv);
        }
        elseif ($this->shard_type == 'user')
        {
            $sub_dir = $this->shard_argv;
        }
        else
        {
            if (empty($this->shard_argv))
            {
                $this->shard_argv = 'Ym/d';
            }
            $sub_dir = date($this->shard_argv);
        }

        //上传的最终绝对路径，如果不存在则创建目录
        $path = rtrim($base_dir, '/') . '/' . ltrim($sub_dir, '/');
        if (!is_dir($path))
        {
            if (mkdir($path, 0777, true) === false)
            {
                $this->error_msg = "mkdir path=$path fail.";
                return false;
            }
        }

        //过滤危险字符
        $_FILES[$name]['name'] = Filter::escape($_FILES[$name]['name']);

        //MIME格式
        $mime = $_FILES[$name]['type'];
        $filetype = $this->getMimeType($mime);
        if ($filetype === 'bin')
        {
            $filetype = self::getFileExt($_FILES[$name]['name']);
        }
        if ($filetype === false)
        {
            $this->error_msg = "File mime '$mime' unknown!";
            $this->error_code = 1;
            return false;
        }
        elseif (!in_array($filetype, $this->allow))
        {
            $this->error_msg = "File Type '$filetype' not allow upload!";
            $this->error_code = 2;
            return false;
        }

        //生成文件名
        if ($filename === null)
        {
            $filename = RandomKey::randtime();
            //如果已存在此文件，不断随机直到产生一个不存在的文件名
            while ($this->exist_check and is_file($path . '/' . $filename . '.' . $filetype))
            {
                $filename = RandomKey::randtime();
            }
        }
        elseif ($this->overwrite === false and is_file($path . '/' . $filename . '.' . $filetype))
        {
            $this->error_msg = "File '$path/$filename.$filetype' existed!";
            $this->error_code = 3;
            return false;
        }
        if ($this->shard_type != 'user')
        {
            $filename .= '.' . $filetype;
        }

        //检查文件大小
        $filesize = filesize($_FILES[$name]['tmp_name']);
        if ($this->max_size > 0 and $filesize > $this->max_size)
        {
            $this->error_msg = "File size go beyond the max_size!";
            $this->error_code = 4;
            return false;
        }
        $save_filename = rtrim($path) . '/' . ltrim($filename);

        $base_url = $this->base_url;
        if (substr($base_url,-1) != "/"){
            $base_url.="/";
        }
        $_sub_dir = "";
        if (!empty($this->sub_dir)){
            $_sub_dir = $this->sub_dir;
            if (substr($_sub_dir,-1) != "/"){
                $_sub_dir .= "/";
            }
        }

    	//写入文件
        if (self::moveUploadFile($_FILES[$name]['tmp_name'], $save_filename))
        {
            //产生缩略图
            if ($this->thumb_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png')))
            {
                $thumb_file = str_replace('.' . $filetype,
                    '_' . $this->thumb_width . 'x' . $this->thumb_height . '.' . $filetype,
                    $filename);
                Image::thumbnail($save_filename,
                    $path . '/' . $thumb_file,
                    $this->thumb_width,
                    $this->thumb_height,
                    $this->thumb_qulitity);
                $return['thumb'] =   $base_url.$_sub_dir."{$sub_dir}/{$thumb_file}";
            }
            //压缩图片
            if ($this->max_width and in_array($filetype, array('gif', 'jpg', 'jpeg', 'bmp', 'png')))
            {
                Image::thumbnail($save_filename,
                    $save_filename,
                    $this->max_width,
                    $this->max_height,
                    $this->max_qulitity);
            }
            $return['url']  = $base_url.$_sub_dir."{$sub_dir}/{$filename}";
            $return['size'] = $filesize;
            $return['type'] = $filetype;
            return $return;
        }
        else
        {
            $this->error_msg = "move upload file fail. tmp_name={$_FILES[$name]['tmp_name']}|dest_name={$save_filename}";
            $this->error_code = 2;
            return false;
        }
    }
1042876
public static function Updatable ($name, $extension = null, $forced_obtain = false) {
		$access_lv = static::GetDetail($name, $extension, $forced_obtain)['access'];
		if ($access_lv === static::PHP_INI_USER) {
			return true;
		}
		if ($access_lv === static::PHP_INI_ALL) {
			return true;
		}
		return false;
	}
140203
public static function getPutParameter(string $name, string $default = null, array $allowed = null): string
    {
        return self::get('PUT', $name, $default, $allowed);
    }
1070744
public function removeFile(string $name, string $field = null): bool
    {
        if (!$name) {
            return false;
        }

        $field = $field ?: 'undefined';

        $upload = $this->files[$field][$name] ?? null;
        if (null !== $upload) {
            $this->removeTmpFile($upload['tmp_name'] ?? '');
        }
        $upload = $this->files[$field . '/original'][$name] ?? null;
        if (null !== $upload) {
            $this->removeTmpFile($upload['tmp_name'] ?? '');
        }

        // Mark file as deleted.
        $this->files[$field][$name] = null;
        $this->files[$field . '/original'][$name] = null;

        unset(
            $this->uploadedFiles[$field][$name],
            $this->uploadedFiles[$field . '/original'][$name]
        );

        return true;
    }
1186920
public function createFile($attribute, $path, $name)
    {
        $handlerCreateFile = $this->fileOption($attribute, 'createFile');
        $file = $handlerCreateFile($path, $name);
        if ($file) {
            $storage = $this->fileStorage($attribute);
            $contents = file_get_contents($path);
            $handlerTemplatePath = $this->fileOption($attribute, 'templatePath');
            if ($storage->write($handlerTemplatePath($file), $contents)) {
                $this->setState($attribute, $file);
                $this->owner->{$attribute} = $file->id;
                return $file;
            }
        } // @codeCoverageIgnore
        return false; // @codeCoverageIgnore
    }
7403
public function save($fileName = null)
	{
		$file = fopen(empty($fileName) ? $this->fileName : $fileName,'w');
		flock($file,LOCK_EX);
		foreach($this->data as $section => $data)
		{
			fwrite($file, '[' . $section . ']' . PHP_EOL);
			foreach($data as $key => $value)
			{
				fwrite($file, $key . '=' . $value . PHP_EOL);
			}
		}
		fclose($file);
	}
1214777
public function save_script($name = null)
    {
        // Kolab's KEP:14
        if ($this->rc->config->get('managesieve_kolab_master')) {
            $this->sieve->script->set_var('EDITOR', self::PROGNAME);
            $this->sieve->script->set_var('EDITOR_VERSION', self::VERSION);
        }

        return $this->sieve->save($name);
    }
611400
private function ValidateAmount($Name, $Value, $AllowEmpty = false)
        {
            if (empty($Value)) {
                // 是否允許空值
                $this->IsAllowEmpty($Name, $AllowEmpty);
            } else {
                // 資料型態檢查
                $this->IsInteger($Name, $Value);

                // 格式檢查
                $this->IsValidFormat($Name, '/^\d+$/', $Value);
            }
        }
87805
public static function getPostParameter(string $name, string $default = null, array $allowed = null): string
    {
        return self::get('POST', $name, $default, $allowed);
    }
102329
public static function save( $fileName, $data, $packetName = NULL )
	{
		if( $packetName === NULL )
			$wddx	= wddx_serialize_value( $data );
		else
			$wddx	= wddx_serialize_value( $data, $packetName );
		return FS_File_Writer::save( $fileName, $wddx );
	}
818364
private function lock($name = null, $blocking = false)
    {
        if (!class_exists(LockHandler::class)) {
            throw new RuntimeException('To enable the locking feature you must install the squire/filesystem component.');
        }

        if (null !== $this->lockHandler) {
            throw new LogicException('A lock is already in place.');
        }

        $this->lockHandler = new LockHandler($name ?: $this->getName());

        if (!$this->lockHandler->lock($blocking)) {
            $this->lockHandler = null;

            return false;
        }

        return true;
    }
791859
public static function check($filename, array $allowedExtension)
    {
        $ext = pathinfo($filename, PATHINFO_EXTENSION);

        if (empty($ext)) {
            return false;
        }

        return in_array($ext, $allowedExtension);
    }
100837
public HttpRequest form(String name, Resource resource) {
		if (null != resource) {
			if (false == isKeepAlive()) {
				keepAlive(true);
			}

			if (null == this.fileForm) {
				fileForm = new HashMap<>();
			}
			// 文件对象
			this.fileForm.put(name, resource);
		}
		return this;
	}
1237506
public function save($path = null, $filename = null)
    {
        $this->path     = isset($path) ? $path : $this->path;
        $this->filename = isset($filename) ? $filename : $this->filename;
        if ( ! file_exists($this->path))
        {
            mkdir($this->path, 0755, true);
        }

        $fh = fopen($this->path.'/'.$this->filename, 'w+');
        fwrite($fh, json_encode($this->settings));
        fclose($fh);
    }
1039414
public static function get($name, $fileName = self::DEFAULT_FILE_NAME, $isDynamic = false, $debug = false)
    {
        static $configFileArr = null;
        static $configData = [];
        if ($debug) {
           return [$configFileArr, $configData];
        }

        $fileName   = str_replace('\\', '/', $fileName);
        $configFile = rtrim( self::getDirPath(), '/').'/'.ltrim($fileName, '/');
        switch (true) {
            case $isDynamic://动态配置
            case !isset($configFileArr[$configFile])://没有设置配置就加载配置文件
                if (!file_exists($configFile)) {
                    throw new ConfigException("$configFile not found", ConfigException::FILE_NOT_FOUND);//配置文件不存在
                }
                $configFileArr[$configFile] = $configFile;
                $config     = include $configFile;
                $configData = array_merge($configData, $config);
                break;

            default:
                break;
        }

        if(!isset($configData[$name])){
            throw new ConfigException('', ConfigException::KEY_NOT_FOUND);
        }
        return $configData[$name];
    }
499791
function allowMapDownload($allow = true, $multicall = false)
    {
        if (!is_bool($allow)) {
            throw new InvalidArgumentException('allow = ' . print_r($allow, true));
        }

        return $this->execute(ucfirst(__FUNCTION__), array($allow), $multicall);
    }
867659
public static function file($name, $options = [])
    {
        self::exclure($options);

        return self::input('file', $name, null, $options);
    }