上传临时素材
@param string $filePath
@param string $type
@return array
@throws Exception
7937
protected function uploadTemp($filePath, $type)
    {
        $url = sprintf(self::MEDIA_TEMP_UPLOAD_URL, $this->getAccessTokenString(), $type);
        $client = $this->getHttpClient();
        $client->setUrl($url);
        $client->setMethod(Client::METHOD_UPLOAD);

        $basename = basename($filePath);

        $client->setPostDataArray([ 'media'          => curl_file_create($filePath),
                                    'filename'      => $basename,
                                    'filelength'    => filesize($filePath),
                                    'content-type'  => $this->getUpLoadContentType($type),
                                    'hack'          => '',
                                    ]);
        if (!$client->exec()) {
            throw new Exception("call send custom service message fail");
        }

        $result = json_decode($client->getResponse(), true);

        if (isset($result['errcode'])) {
            throw new Exception("error response for upload Temp info " . $result['errcode'] . ' ' . $result['errmsg']);
        }

        return $result;
    }
659337
public function loadFile($filePath)
    {
        if ($filePath instanceof \SplFileInfo) {
            $filePath = $filePath->getRealPath();
        }

        if (is_file($filePath)) {
            return $this->loadString(file_get_contents($filePath));
        }

        return false;
    }
27412
public static function openFile(/*string*/ $filePath, /*string*/ $mode) {
    return self::isFile($filePath) ? fopen($filePath, $mode, false) : false;
  }
724460
public function save( $filePath ){
		$data	= array();
		foreach( $this->index() as $route ){
			$data[]	= array(
				'controller'	=> $route->getController(),
				'action'		=> $route->getAction(),
				'pattern'		=> $route->getPattern(),
				'method'		=> $route->getMethod(),
			);
		}
		return \FS_File_JSON_Writer::save( $filePath, $data, TRUE );
	}
1363967
public static function create(string $path, string $type):int
    {
        try {
            switch ($type) {
                case "directory":
                    if (!is_dir($path)) {
                        mkdir($path);
                    }
                    break;
                case "file":
                    if (!is_file($path)) {
                        touch($path);
                    }
                    break;
            }
        } catch (\Exception $exception) {
            throw new \Exception("Server Error : Cannot create $type element => ".$exception);
        }

        return (1);
    }
1151899
private function replaceDummyInFile($filePath)
    {
        $fileSource = File::get($filePath);
        $fileContent = str_replace(array_keys($this->dummyReplacements), array_values($this->dummyReplacements), $fileSource);
        $writeFile = File::put($filePath, $fileContent);
        if ($writeFile === false) {
            throw new \Exception("Error writing to file " . $filePath);
        }
    }
830062
public function file($path, $type = 'debug')
    {
        $this->pushHandler(new StreamHandler($path, $this->getLevel($type)));
    }
4664
public function uploadFile($filePath, $key = null, $bucket = '')
    {
        if (!file_exists($filePath)) {
            throw new \Exception("上传的文件不存在",400);
        }
        $bucket = $bucket ? $bucket : $this->bucket;

        $uploadToken = $this->uploadToken(array('scope' => $bucket));
        $data = [];
        if (class_exists('\CURLFile')) {
            $data['file'] = new \CURLFile($filePath);
        } else {
            $data['file'] = '@' . $filePath;
        }
        $data['token'] = $uploadToken;
        if ($key) {
            $data['key'] = $key;
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->up_host);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $result = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        $result = $this->response($result);
        if ($status == 200) {
            return $result;
        } else {
            throw new \Exception($result['error'],$status);
        }
    }
994431
public function open(string $filePath, string $mode)
    {
        $this->exists($filePath, $mode);

        $ptr = @fopen($filePath, $mode);

        if (false === $ptr) {
            throw new FileException("Unable to open $filePath.");
        }

        return $ptr;
    }
886575
public function locate($filePath)
    {
        $file = $filePath;
        if (!is_file($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" does not exist.',
                                            $filePath));
        }

        if (!is_readable($filePath))
        {
            throw new FileException(sprintf('Invalid file! File "%s" is not readable.',
                                            $filePath));
        }

        $pathInfo = pathinfo($filePath);
        if (!isset($pathInfo['extension'])
            || !in_array($pathInfo['extension'], $this->supportedExtensions)
        )
        {
            throw new FileException(sprintf('Invalid file extension! Supported file extensions: %s',
                implode(', ', $this->supportedExtensions)));
        }

        return realpath($file);
    }
566293
private function dispatchEvent($eventType, $filePath)
    {
        if (null !== $this->eventDispatcher) {
            $relativePath = $this->fs->makePathRelative(dirname($filePath), $this->root) . basename($filePath);
            $this->eventDispatcher->dispatch(
                $eventType,
                new ResourceEvent($relativePath, $this->httpRoot, $this->root)
            );

            if (null !== $this->imagineConfig) {
                if (false !== strpos($relativePath, '/../') || 0 === strpos($relativePath, '../')) {
                    // outside web root, stop.
                    return;
                }

                // Create events for the imagine cache as well.

                /** @var CacheManager $cacheManager */
                /** @var FilterConfiguration $filterConfig */
                list ($cacheManager, $filterConfig) = $this->imagineConfig;
                $webPath = $this->httpRoot . '/' . $relativePath;
                $cacheManager->remove($webPath);

                foreach ($filterConfig->all() as $name => $filter) {
                    $url = $cacheManager->resolve($webPath, $name);

                    // this weird construct is here because the imagine cache manager generates absolute urls
                    // even though they're local for some unapparent reason.
                    $relativeUrl = parse_url($url, PHP_URL_PATH);
                    $url = $this->fs->makePathRelative(dirname($relativeUrl), $this->httpRoot) . basename($relativeUrl);

                    if (false === strpos($url, '../')) {
                        $this->eventDispatcher->dispatch(
                            $eventType,
                            new ResourceEvent($url, $this->httpRoot, $this->root)
                        );
                    }
                }
            }
        }
    }
1346640
public static function __include( $classPath, $type = IMPORT_APP, $extension=EXT_PHP ) {

        //组合文件路径
        switch ( $type ) {

            case IMPORT_APP :
                $path = APP_PATH.'/modules/';
                break;

            case IMPORT_CUSTOM :
                $path = APP_ROOT;
                break;

            default:
                return false;
        }

        $classPath = str_replace('.', '/', $classPath);
        return include $path.$classPath.$extension;
    }
767810
public function createReader($filePath, $delimiter = ReaderInterface::DELIMITER_DEFAULT, $fileCharset = ReaderInterface::CHARSET_DEFAULT, $mode = 'r', $type = null)
    {
        if (null === $type) {
            $type = $this->getDefaultReaderType();
        }

        return $this->getReaderFactory()->createReader($type, $filePath, $delimiter, $fileCharset, $mode);
    }
1152369
public function uploadPhotoFromPath($eventId, $filepath, $albumId = null)
    {
        if (is_null($eventId) || $eventId == '') {
            throw new Exception('The eventId is required to upload a file.');
        }

        if (is_null($filepath) || $filepath == '') {
            throw new Exception('The filepath is required to upload a file.');
        }

        if (!file_exists($filepath)) {
            throw new Exception('The filepath does not point to an accessible file.');
        }

        $params = array(
            'method' => 'sp.photo.upload',
            'event_id' => $eventId,
            'album_id' => $albumId
        );

        $photos = array(
            'photo' => new CURLFile($filepath),
        );

        return $this->_makeApiRequest($params, $photos);
    }
146716
public static function detect($filePath, string $type = null)
    {
        if (null !== $type) {
            return $type;
        }

        if (!$filePath instanceof UploadedFile) {
            $pathInfo  = pathinfo($filePath);
            $extension = $pathInfo['extension'] ?? '';
        } else {
            $extension = $filePath->getClientOriginalExtension();
        }

        if (null === $type && trim($extension) === '') {
            throw new NoTypeDetectedException();
        }

        return config('excel.extension_detector.' . strtolower($extension));
    }
303047
public function createWriter($filePath, $delimiter = WriterInterface::DELIMITER_DEFAULT, $fileCharset = WriterInterface::CHARSET_DEFAULT, $mode = 'w', $type = null)
    {
        if (null === $type) {
            $type = $this->getDefaultWriterType();
        }

        return $this->getWriterFactory()->createWriter($type, $filePath, $delimiter, $fileCharset, $mode);
    }
1332275
public function readFile($filePath)
    {
        if (false === $fileContent = @file_get_contents($filePath)) {
            throw new RuntimeException(
                sprintf('unable to read file "%s"', $filePath)
            );
        }

        return $fileContent;
    }