上传文件

@param mixed $path
@param string $type
@param array $option
@return array
503217
public function upload($path, $type = '', $option = [])
    {
        if (is_array($path)) {
            return $this->uploadByFile($path, $type, $option);
        } elseif (is_file($path)) {
            return $this->uploadByPath($path, $type, $option);
        } else {
            return $this->uploadByUrl($path, $type, $option);
        }
    }
1073671
public function fileOpen($path, $mode, $options, &$entity)
  {
    $entity = $this->getEntity($path);

    $filePointer = null;
    if (!is_null($entity)) {
      $exists = $entity->file_exists();

      if ($exists && !$entity->is_file()) {
        $filePointer = null;
      } else {
        $fopenWillFail = false;
        $mode = strtolower($mode);
        if ($mode != "r") {
          $isVirtual = ($entity instanceof Entity_Virtual_Interface);
          if (!$exists || !$isVirtual) {
            /* @var $entity Entity */
            $tmpPath = $this->_files->tempnam();
            $basename = basename($path);

            if ($exists) {
              if ($mode == "x" || $mode == "x+") {
                $fopenWillFail = true;
              } else {
                copy($entity->path(), $tmpPath);
              }
            }
            if (!$fopenWillFail) {
              $entity = Entity_Virtual::newInstance(
                $entity, $tmpPath, $basename
              );

              $changes = $this->getChanges();
              $changes->add($path, $entity);
            }
          }
        }

        if ($fopenWillFail) {
          $entity = null;
        } else {
          if ($options & STREAM_REPORT_ERRORS) {
            $filePointer = fopen($entity->path(), $mode);
          } else {
            $filePointer = @fopen($entity->path(), $mode);
          }
        }
      }
    }

    return $filePointer;
  }
597611
function(_path, _type, _str){
        var file = $options.path+"/"+_path+"."+_type;
        $fs.appendFile(file, _str, 'utf8');
    }
376224
public function fileOpen(string $path, string $mode, int $options)
    {
        $entity = $this->getEntity($path);

        $filePointer = null;
        if (null !== $entity) {
            $exists = $entity->file_exists();

            if ($exists && !$entity->is_file()) {
                $filePointer = null;
            } else {
                $fopenWillFail = false;
                $mode = strtolower($mode);
                if ('r' != $mode) {
                    $isVirtual = ($entity instanceof VirtualInterface);
                    if (!$exists || !$isVirtual) {
                        $tmpPath = $this->tempnam();
                        $basename = basename($path);

                        if ($exists) {
                            if ('x' == $mode || 'x+' == $mode) {
                                $fopenWillFail = true;
                            } else {
                                copy($entity->path(), $tmpPath);
                            }
                        }
                        if (!$fopenWillFail) {
                            $entity = Virtual::newInstance(
                                $entity, $tmpPath, $basename
                            );

                            $changes = $this->getChanges();
                            $changes->add($path, $entity);
                        }
                    }
                }

                if ($fopenWillFail) {
                    $entity = null;
                } else {
                    if ($options & STREAM_REPORT_ERRORS) {
                        $filePointer = fopen($entity->path(), $mode);
                    } else {
                        $filePointer = @fopen($entity->path(), $mode);
                    }
                }
            }
        }

        return $filePointer;
    }
215346
protected function request($path, $params = [], $type = 'GET')
    {
        $apiUrl = 'https://my.ipaymu.com';

        $uri = (new Uri($apiUrl))->withPath($path);
        $request = new Curl\Request();

        $params[ 'key' ] = $this->config['apiKey'];
        $params[ 'format' ] = 'json';

        switch ($type) {
            default:
            case 'GET':
                $this->response = $request->setUri($uri)->get($params);
                break;

            case 'POST':
                $request->addHeader('content-type', 'application/x-www-form-urlencoded');
                $this->response = $request->setUri($uri)->post($params);
                break;
        }

        // Try to get curl error
        if (false !== ($error = $this->response->getError())) {
            $this->errors = $error;
        } else {
            $body = $this->response->getBody();

            if (empty($body[ 'Status' ])) {
                return $body->getArrayCopy();
            } else {
                $this->errors[ $body[ 'Status' ] ] = $body[ 'Keterangan' ];
            }
        }

        return false;
    }
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;
    }
774435
public function uploadFile($filepath,$type=2) {
		$send_snoopy = new Snoopy;
		$send_snoopy->referer = "http://mp.weixin.qq.com/cgi-bin/indexpage?t=wxm-upload&lang=zh_CN&type=2&formId=1";
		$t = time().strval(mt_rand(100,999));
		$post = array('formId'=>'');
		$postfile = array('uploadfile'=>$filepath);
		$send_snoopy->rawheaders['Cookie']= $this->cookie;
		$send_snoopy->set_submit_multipart();
		$submit = "http://mp.weixin.qq.com/cgi-bin/uploadmaterial?cgi=uploadmaterial&type=$type&token=".$this->_token."&t=iframe-uploadfile&lang=zh_CN&formId=	file_from_".$t;
		$send_snoopy->submit($submit,$post,$postfile);
		$tmp = $send_snoopy->results;
		$this->log('upload:'.$tmp);
		preg_match("/formId,.*?\'(\d+)\'/",$tmp,$matches);
		if (isset($matches[1])) {
			return $matches[1];
		}
		return false;
	}
90544
public static function addToQueue($path, $type)
    {
        if ($type != self::TYPE_DIR && $type != self::TYPE_FILE) {
            throw new \Exception(sprintf('Invalid $type parameter "%s"', $type));
        }

        self::$cleanupQueue[] = ['path' => $path, 'type' => $type];
    }
718244
public function saveTo($path , $type='png', $quality=null)
	{
		if (!$path) return false;
		return $this->outputTo($path, $type, $quality);
	}
60661
private function process_paths( $type, $paths ) {

		foreach ( $paths as $path ) {
			$has_struct = $this->get_file_structure( $path );
			if ( is_array( $has_struct ) ) {
				$this->add_objects( $type, $has_struct );
			}
		}
	}
1027150
public function remove_path($path, $type = null)
	{
		is_null($type) and $type = $this->_path_folders;

		if( is_array($type))
		{
			foreach ($type as $key => $folder)
			{
				is_numeric($key) and $key = $folder;
				$folder = $this->_unify_path($path).ltrim($this->_unify_path($folder),DS);
				if (($found = array_search($folder, $this->_asset_paths[$key])) !== false)
				{
					unset($this->_asset_paths[$key][$found]);
				}
			}
		}
		else
		{
			$path = $this->_unify_path($path);
			if (($key = array_search($path, $this->_asset_paths[$type])) !== false)
			{
				unset($this->_asset_paths[$type][$key]);
			}
		}

		return $this;
	}
1119829
public function uploadFile($path, $target_path)
    {
        // 允许客户端断开连接
        ignore_user_abort(true);
        
        try {
            // 文件大于设定值进行分片上传
            $file_size = filesize($path);
            $save_path = $this->option('root') . $target_path;
            if ($file_size > $this->option('maxsize') * 1048576) {
                $data = array(
                    'return_url' => $this->option('return'),
                    'notify_url' => $this->option('notify')
                );
                $stream = Psr7\stream_for(fopen($path, 'rb'));
                $rsp = $this->getUpYunChunk()->upload($save_path, $stream, md5_file($path), $data);
            } else {
                $fh = fopen($path, 'r');
                $rsp = $this->getUpYun()->write($save_path, $fh);
            }
            
            // 拼接链接
            $url = $this->option('url') . $target_path;
            return Format::formatResult(1, '上传成功', $url);
        } catch (\Exception $e) {
            return Format::formatResult(0, '上传文件发生意外:' . $e->getLine() . $e->getFile() . $e->getMessage());
        }
    }
511793
public function add_type($type, $path = null)
	{
		isset($this->_asset_paths[$type]) or $this->_asset_paths[$type] = array();
		isset($this->_path_folders[$type]) or $this->_path_folders[$type] = $type.'/';

		if ( ! is_null($path))
		{
			$path = $this->_unify_path($path);
			$this->_asset_paths[$type][] = $path;
		}

		return $this;
	}
21595
public function addOption( $opt, $type ) {
        if( $type !== self::OPT_PARAM || $type !== self::OPT_SWITCH ) {
            return;
        }
        
        $this->options[(string)$opt] = $type;
    }
393660
public function putFile($path, $file, $options = [])
    {
        return $this->putFileAs($path, $file, $file->getRename(), $options);
    }
753122
public function stream_metadata($path, $option, $value)
    {
        $container = $this->getContainerFromContext($path);
        $strippedPath = $this->stripScheme($path);

        try {

            if ($option == STREAM_META_TOUCH) {
                if (!$container->hasNodeAt($strippedPath)) {
                    try {
                        $container->createFile($strippedPath);
                    } catch (NotFoundException $e) {
                        trigger_error(
                            sprintf('touch: %s: No such file or directory.', $strippedPath),
                            E_USER_WARNING
                        );

                        return false;
                    }
                }
                $file = $container->nodeAt($strippedPath);

                $permissionHelper = $container->getPermissionHelper($file);

                if (!$permissionHelper->userIsOwner() && !$permissionHelper->isWritable()) {
                    trigger_error(
                        sprintf('touch: %s: Permission denied', $strippedPath),
                        E_USER_WARNING
                    );

                    return false;
                }

                $time = isset($value[0]) ? $value[0] : time();
                $atime = isset($value[1]) ? $value[1] : $time;

                $file->setChangeTime($time);
                $file->setModificationTime($time);
                $file->setAccessTime($atime);

                clearstatcache(true, $path);

                return true;

            }

            $node = $container->nodeAt($strippedPath);
            $permissionHelper = $container->getPermissionHelper($node);

            switch ($option) {
                case STREAM_META_ACCESS:

                    if ($node instanceof Link) {
                        $node = $node->getDestination();
                        $permissionHelper = $container->getPermissionHelper($node);
                    }

                    if (!$permissionHelper->userIsOwner()) {
                        trigger_error(
                            sprintf('chmod: %s: Permission denied', $strippedPath),
                            E_USER_WARNING
                        );

                        return false;
                    }
                    $node->chmod($value);
                    $node->setChangeTime(time());
                    break;

                case STREAM_META_OWNER_NAME:
                    if (!$permissionHelper->userIsRoot() && !$permissionHelper->userIsOwner()) {
                        trigger_error(
                            sprintf('chown: %s: Permission denied', $strippedPath),
                            E_USER_WARNING
                        );

                        return false;
                    }
                    $uid = function_exists('posix_getpwnam') ? posix_getpwnam($value)['uid'] : 0;
                    $node->chown($uid);
                    $node->setChangeTime(time());
                    break;

                case STREAM_META_OWNER:
                    if (!$permissionHelper->userIsRoot() && !$permissionHelper->userIsOwner()) {
                        trigger_error(
                            sprintf('chown: %s: Permission denied', $strippedPath),
                            E_USER_WARNING
                        );

                        return false;
                    }
                    $node->chown($value);
                    $node->setChangeTime(time());
                    break;

                case STREAM_META_GROUP_NAME:
                    if (!$permissionHelper->userIsRoot() && !$permissionHelper->userIsOwner()) {
                        trigger_error(
                            sprintf('chgrp: %s: Permission denied', $strippedPath),
                            E_USER_WARNING
                        );

                        return false;
                    }
                    $gid = function_exists('posix_getgrnam') ? posix_getgrnam($value)['gid'] : 0;
                    $node->chgrp($gid);
                    $node->setChangeTime(time());
                    break;

                case STREAM_META_GROUP:
                    if (!$permissionHelper->userIsRoot() && !$permissionHelper->userIsOwner()) {
                        trigger_error(
                            sprintf('chgrp: %s: Permission denied', $strippedPath),
                            E_USER_WARNING
                        );

                        return false;
                    }
                    $node->chgrp($value);
                    $node->setChangeTime(time());
                    break;
            }
        } catch (NotFoundException $e) {
            return false;
        }

        clearstatcache(true, $path);

        return true;
    }
579386
private function filter($items, $path, $type)
    {
        if (!$items) {
            return null;
        }

        return array_filter($items, function ($item) use ($path, $type) {
            $itemCopy = $item;

            // key into the value with the given path
            foreach ($path as $key) {
                $itemCopy = $itemCopy[$key];
            }

            if (strtolower($itemCopy) === strtolower($type)) {
                return $item;
            }
        });
    }