【问题标题】:Symfony2 Gaufrette How to create directory?Symfony2 Gaufrette 如何创建目录?
【发布时间】:2014-02-11 05:18:56
【问题描述】:

问题是如何在我的文件系统中创建新文件夹? 我知道如何添加文件,但是如何在指定路径中创建一个空文件夹?

【问题讨论】:

    标签: symfony filesystems gaufrette


    【解决方案1】:

    我正在使用 Amazon S3 适配器,并且能够使用以下内容创建目录:

    use Gaufrette\Filesystem;
    use Gaufrette\Adapter\AwsS3;
    use Aws\S3\S3Client;
    
    $s3Service = S3Client::factory(array("key" => "Your Key Here", "secret" => "Your AWS Secret Here" ));
    $adapter  = new AwsS3($s3Service,"yourBucketNameHere");
    $filesystem = new Filesystem($adapter);
    
    $filesystem->write("new-directory-here/", "");
    

    【讨论】:

      【解决方案2】:

      然后您调用write aapter 确保该目录存在。例如Ftp

      public function write($key, $content)
      {
          $this->ensureDirectoryExists($this->directory, $this->create);
      
          $path = $this->computePath($key);
          $directory = dirname($path);
      
          $this->ensureDirectoryExists($directory, true);
      
          ...
      }
      

      /**
       * Ensures the specified directory exists. If it does not, and the create
       * parameter is set to TRUE, it tries to create it
       */
      protected function ensureDirectoryExists($directory, $create = false)
      {
          ...
      }
      

      【讨论】:

        【解决方案3】:

        只需将true 传递给Local 适配器:

        use Gaufrette\Adapter\Local as LocalAdapter;
        
        ...
        
        $adapter = new LocalAdapter(__DIR__ . '/your-new-dir', true);
        $filesystem = new Filesystem($adapter);
        

        【讨论】:

          猜你喜欢
          • 2015-10-21
          • 2021-09-20
          • 1970-01-01
          • 2016-11-30
          • 1970-01-01
          • 1970-01-01
          • 2010-10-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多