根据路径上传

@param string $path
@param string $type
@param array $option
@return array
196839
public function uploadByPath($path, $type = '', $option = [])
    {
        // 文件是否存在
        if (empty($path) || ! is_file($path)) {
            return Format::formatResult(0, '文件不存在');
        }
        
        // 没有指定后缀
        if (! isset($option['ext'])) {
            $option['ext'] = FileInfo::getFileExt($path);
        }
        
        // 类型识别出错
        if (empty($option['ext']) && isset($option['mime'])) {
            $option['ext'] = FileInfo::mimeToExt($option['mime']);
        }
        
        // 上传文件类型
        $type = $this->getFileType($option['ext'], $type);
        if (empty($type)) {
            return Format::formatResult(0, '不合法的文件类型');
        }
        
        // 处理图片
        $type == 'image' && $this->processImage($path, $option);
        
        // 没有文件Md5
        if (! isset($option['hash'])) {
            $option['hash'] = md5_file($path);
        }
        
        // 是否上传过
        if ($this->onCheck && is_callable($this->onCheck)) {
            $url = call_user_func($this->onCheck, [
                'hash' => $option['hash'],
                'type' => $type,
                'ext' => $option['ext'],
                'path' => $path
            ]);
            
            // 文件存在
            if (! empty($url)) {
                return Format::formatResult(1, '上传成功', [
                    'url' => $url,
                    'hash' => $option['hash'],
                    'type' => $type,
                    'ext' => $option['ext'],
                    'path' => $this->option('root') . DS . $type . DS . $option['hash'] . '.' . $option['ext']
                ]);
            }
        }
        
        // 上传文件
        $target_path = $type . '/' . $option['hash'] . '.' . $option['ext'];
        $res = $this->uploadFile($path, $target_path);
        
        // 上传完成
        $this->onDone && is_callable($this->onDone) && call_user_func($this->onDone, [
            'hash' => $option['hash'],
            'type' => $type,
            'ext' => $option['ext'],
            'path' => $path
        ]);
        
        // 上传失败
        if ($res['code'] != 1) {
            $this->onError && is_callable($this->onError) && call_user_func($this->onError, [
                'hash' => $option['hash'],
                'type' => $type,
                'ext' => $option['ext'],
                'path' => $path
            ]);
            return $res;
        }
        
        // 上传成功
        $this->onSuccess && is_callable($this->onSuccess) && call_user_func($this->onSuccess, [
            'hash' => $option['hash'],
            'type' => $type,
            'ext' => $option['ext'],
            'path' => $path,
            'url' => $res['data']
        ]);
        
        // 返回结果
        return Format::formatResult(1, '上传成功', [
            'url' => $res['data'],
            'hash' => $option['hash'],
            'type' => $type,
            'ext' => $option['ext'],
            'path' => $this->option('root') . DS . $type . DS . $option['hash'] . '.' . $option['ext']
        ]);
    }
909171
public function uploadFrom($file, $type = 'image')
    {
        if (!$file || !$type) {
            $this->setError('参数缺失');

            return false;
        }

        $this->setPostQueryStr('type', $type);

        $name        = 'media'; // 设置上传文件键名 固定为media
        $filename    = $file['name']; // 设置上传文件名
        $filetype    = $file['type'];
        $filecontent = file_get_contents($file['tmp_name']); // 读取临时文件里 上传文件的信息
        $key         = "name=\"{$name}\"; filename=\"{$filename}\"\r\nContent-Type: {$filetype}\r\n"; // curl设置上传文件的一种方法.

        $param       = [];
        $param[$key] = $filecontent;

        $node = 'upload';

        $res = $this->_post($node, $param, false);

        return $res;
    }
1033440
public function optionFlush($type = null)
    {
        if (in_array($type, ['modules', 'languages'])) {
            switch ($type) {
                case 'modules':
                    modules()->flushRegistry();
                    break;

                case 'languages':
                    language()->flushRegistry();
                    break;
            }

        } else {
            modules()->flushRegistry();
            language()->flushRegistry();
        }

        exit(EXIT_SUCCESS);
    }
1115120
public function upload(string $type, string $path): array
    {
        return $this->httpClient->postFile('media/upload', $path, compact('type'));
    }
1286836
public static function getFileExt($path, $type = self::MIME_FINFO)
    {
        $mime = self::getFileMime($path, $type);
        return $mime ? self::mimeToExt($mime) : null;
    }
8467
public function setPath($type, $path)
	{
		if (!array_key_exists($type, $this->paths))
		{
			throw new \Exception(\App::get('language')->txt('Unknown asset path type of %s given.', $type));
		}

		$path = trim((string) $path);

		// Add separators as needed
		$path = DS . trim($path, DS);

		// Add to list of paths
		$this->paths[$type] = $path;

		return $this;
	}
259114
public function get($index, $type, $id, $options = [])
    {
        return $this->db->get([$index, $type, $id], $options);
    }
865701
public function upload($type, $path)
    {
        if (!file_exists($path) || !is_readable($path)) {
            throw new InvalidArgumentException("File does not exist, or the file is unreadable: '$path'");
        }

        if (!in_array($type, $this->allowTypes, true)) {
            throw new InvalidArgumentException("Unsupported media type: '{$type}'");
        }

        return $this->parseJSON('upload', [self::API_UPLOAD, ['media' => $path], [], ['type' => $type]]);
    }
42757
public function addOption($type, $value = true)
    {
        //====================================================================//
        // Safety Checks ==> Verify a new Field Exists
        if (empty($this->new)) {
            Splash::log()->err("ErrFieldsNoNew");
        } elseif (empty($type)) {
            Splash::log()->err("Field Option Type Cannot be Empty");
        } else {
            //====================================================================//
            // Update New Field structure
            $this->new->options[$type] = $value;
        }

        return $this;
    }
37716
public function readEventConfiguration($path, $type)
    {
        if (!file_exists($path)) {
            throw new \InvalidArgumentException('File ' . $path . 'don\'t exists.');
        }

        $name = '\BlueEvent\Event\Config\\' . ucfirst($type) . 'Config';

        if (!class_exists($name)) {
            throw new \InvalidArgumentException('Incorrect configuration type: ' . $type);
        }

        /** @var \BlueEvent\Event\Config\ConfigReader $reader */
        $reader = new $name;

        return $this->setEventConfiguration($reader->readConfig($path));
    }
1191305
protected function _append($type, $path, $options, $rel = null) {
		foreach ((array) $path as $i) {
			$this->{$type}[$i] = compact('options', 'rel');
		}
	}
899569
public static function delete(string $path, string $type):int
    {
        try {
            switch ($type) {
                case "directory":
                    if (is_link($path)) {
                        unlink($path);
                    } elseif (is_dir($path)) {
                        try {
                            self::recursiveRmdir($path);
                        } catch (\Exception $e) {
                            throw new \Exception("Server Manager delete error =>" . $e->getMessage());
                        }
                    }
                    break;
                case "file":
                    if (is_link($path)) {
                        unlink($path);
                    } elseif (file($path)) {
                        try {
                            unlink($path);
                        } catch (\Exception $e) {
                            throw new \Exception("Server Manager delete error =>" . $e->getMessage());
                        }
                    }
                    break;
            }
        } catch (\Exception $exception) {
            throw new \Exception("Server Error : Cannot delete $type element => ".$exception);
        }

        return (1);
    }
390184
public static function ensureConfigFile($path, $type)
    {
        if (!is_file($path)) {
            $content = self::getExampleConfiguration($type);
            file_put_contents($path, $content);
        }
    }
830062
public function file($path, $type = 'debug')
    {
        $this->pushHandler(new StreamHandler($path, $this->getLevel($type)));
    }
438887
public function urlFor($path, $type_name = 'asset', array $params = array())
    {
        switch ($type_name) {
            case 'asset':
                return $this->container->getRequest()->getRootUri() . $path;
                break;
            case 'route':
                $routeUrl = $this->container->getRequest()->getRootUri($this->getSetting('debug')) . $this->container->getRoute($path)->getPatternUri();
                return (!empty($params)) ? $routeUrl . '?' . http_build_query($params) : $routeUrl;
                break;
        }
    }
371780
public function FileToDOCX($path, GrabzItDOCXOptions $options = null)
	{
		if (!file_exists($path))
		{
			throw new GrabzItException("File: " . $path . " does not exist", GrabzItException::FILE_NON_EXISTANT_PATH);
		}
		
		$this->HTMLToDOCX(file_get_contents($path), $options);
	}
972206
public function request($method, $path, $query, $body = [], $type = 'json')
    {
        // reset errors
        $this->errorMessages = [];

        $query['wt'] = 'json';
        $request = [
            'Accept' => 'application/json',
            'query' => $query
        ];

        if ($method != 'GET') {
            $request[$type] = $body;
        }

        try {
            $res = $this->client->request($method, $path, $request);

            return json_decode($res->getBody()->getContents(), true);
        } catch (RequestException $e) {
            if ($e->getResponse() === null) {
                $this->logError($e->getMessage());

                return false;
            }

            // 4xx
            if ($e->getResponse()->getStatusCode() == 400) {
                $content = $e->getResponse()->getBody()->getContents();
                $this->logError($content);

                return json_decode($content, true);
            }

            if ($e->getResponse()->getStatusCode() === 404) {
                $this->logError('404. Path: '.$e->getRequest()->getUri()->getPath(). " doesn't exist");

                return false;
            }

            $this->logError($e->getMessage());

            return false;
        }
    }