【发布时间】:2014-02-11 05:18:56
【问题描述】:
问题是如何在我的文件系统中创建新文件夹? 我知道如何添加文件,但是如何在指定路径中创建一个空文件夹?
【问题讨论】:
标签: symfony filesystems gaufrette
问题是如何在我的文件系统中创建新文件夹? 我知道如何添加文件,但是如何在指定路径中创建一个空文件夹?
【问题讨论】:
标签: symfony filesystems gaufrette
我正在使用 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/", "");
【讨论】:
然后您调用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)
{
...
}
【讨论】:
只需将true 传递给Local 适配器:
use Gaufrette\Adapter\Local as LocalAdapter;
...
$adapter = new LocalAdapter(__DIR__ . '/your-new-dir', true);
$filesystem = new Filesystem($adapter);
【讨论】: