Symfony2 Gaufrette How to create directory?

3.3k views Asked by At

the question is how can i create new folder in my filesystem ? I know how to add file, but how to create an empty folder in specified path ?

3

There are 3 answers

0
Alexey B. On

Then you call write apapter ensure that directory exist. For example 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)
{
    ...
}
0
handlebar_ On

I'm using the Amazon S3 adaptor, and am able to create a directory using the following:

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/", "");
0
Aerendir On

Simply pass true to the Local adapter:

use Gaufrette\Adapter\Local as LocalAdapter;

...

$adapter = new LocalAdapter(__DIR__ . '/your-new-dir', true);
$filesystem = new Filesystem($adapter);