You are here

public function AmazonS3StreamWrapper::mkdir in AmazonS3 7

Support for mkdir().

Parameters

string $uri: A string containing the URI to the directory to create.

int $mode: Permission flags - see mkdir().

int $options: A bit mask of STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE.

Return value

bool TRUE if directory was successfully created.

Overrides StreamWrapperInterface::mkdir

See also

http://php.net/manual/en/streamwrapper.mkdir.php

File

./AmazonS3StreamWrapper.inc, line 787
Drupal stream wrapper implementation for Amazon S3

Class

AmazonS3StreamWrapper
@file Drupal stream wrapper implementation for Amazon S3

Code

public function mkdir($uri, $mode, $options) {
  $this
    ->assertConstructorCalled();
  $recursive = (bool) ($options & STREAM_MKDIR_RECURSIVE);
  $localpath = $this
    ->getLocalPath($uri);

  // s3 has no concept of directories, but we emulate it by creating an
  // object of size 0 with a trailing "/"
  try {
    $response = $this
      ->getS3()
      ->create_object($this->bucket, $localpath . '/', array(
      'body' => '',
    ));
    if ($response
      ->isOk()) {
      return TRUE;
    }
  } catch (Exception $e) {
    watchdog('amazons3', 'Unable to create directory @path', array(
      '@path' => $localpath,
    ), WATCHDOG_NOTICE);
  }
  return FALSE;
}