Services_Amazon_S3
[ class tree: Services_Amazon_S3 ] [ index: Services_Amazon_S3 ] [ all elements ]

Class: Services_Amazon_S3_Stream

Source Location: /Services_Amazon_S3-0.4.0/Services/Amazon/S3/Stream.php

Class Overview


Services_Amazon_S3_Stream is a stream wrapper for Amazon S3. With this, buckets and objects can be manipulated using the PHP filesystem functions, e.g. fopen(), file_put_contents(), file_exists() etc.


Author(s):

Version:

  • Release: @release-version@

Copyright:

  • 2008-2009 Peytz & Co. A/S, 2011 silverorange, Inc

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 127]
Services_Amazon_S3_Stream is a stream wrapper for Amazon S3. With this, buckets and objects can be manipulated using the PHP filesystem functions, e.g. fopen(), file_put_contents(), file_exists() etc.

S3 has no notion of directories but support emulation to some extent using the prefix and delimiter parameters when listing keys in a bucket.

The path "s3://mybucket/myprefix/bar" corresponds to the object key "myprefix/bar" in the bucket called "mybucket". "s3://mybucket/myprefix" is considered a directory containing all objects with keys beginning with "myprefix".

This class is used by the PHP stream wrapper API and shouldn't be called directly, except for Services_Amazon_S3_Stream::register().

Various options may be specified using Services_Amazon_S3_Stream::register() or using a PHP stream context.

Available options are:

  • access_key_id string 20-character key id
  • secret_access_key string 40-character secred key
  • http_config array is mapped to $s3->httpConfig
  • http_options array deprecated alias for http_config
  • use_ssl bool maps to $s3->useSSL
  • request_style string maps to $s3->requestStyle
  • endpoint string maps to $s3->endpoint
  • acl string|Services_Amazon_S3_AccessControlList applies this ACL to new files
  • strict bool use strict mode (see below) - the default is false
  • dns_strict bool use strict mode for dns names (see below) - the default is true
  • content_type string maps to $s3->contentType

The wrapper assumes that all paths names are encoded in UTF-8.

Strict Mode:

S3 buckets has no directory structure but just treats a path with slashes as verbatim string. Contrary to a regular filesystem this makes it possible to create an object with the key "foo/bar/baz" without "foo/bar" being created in advance. When strict mode is enabled, this wrapper makes extra sanity checks to ensure that a directory exists before accessing it using opendir() or creating a file or directory inside it using fopen() or mkdir(). Also it verified that a file exists when calling unlink(), and that a directory does not already exist when calling mkdir(). These extra sanity checks require additional requests to the server. Most code will not require these checks, so by default strict mode is disabled.

DNS Strict Mode:

S3 can use a virtual-host style method of accessing buckets (i.e. mybucket.s3.amazonaws.com). When DNS strict mode is enabled (default) the name of buckets must conform to the suggested bucket name syntax. This means underscores are forbidden. When DNS strict mode is disabled, underscores can be used for bucket names.



[ Top ]


Class Variables

$context =

[line 149]

If a stream context is specified when creating the stream, this property is set by PHP.
  • Access: public

Type:   resource|null


[ Top ]



Method Detail

dir_closedir   [line 901]

bool dir_closedir( )

Support for closedir().

[ Top ]

dir_opendir   [line 774]

bool dir_opendir( string $path, string $options)

Support for opendir().

Parameters:

string   $path   —  the path to the directory
string   $options   —  unknown (parameter is not documented in PHP Manual)

[ Top ]

dir_readdir   [line 828]

string|bool dir_readdir( )

Support for readdir().

[ Top ]

dir_rewinddir   [line 881]

bool dir_rewinddir( )

Support for rewinddir().

[ Top ]

mkdir   [line 625]

bool mkdir( string $path, int $mode, int $options)

Support for mkdir().

Parameters:

string   $path   —  the directory path
int   $mode   —  permission flags - see mkdir()
int   $options   —  a bit mask of STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE

[ Top ]

register   [line 275]

void register( [string $wrapper = 's3'], [array $options = array()])

Register this stream wrapper with the specified prefix and options.

Unless anonymous access is wanted, the common way to register the wrapper is this:

  1.    array('access_key_id'     => '0PN5J17HBGZHT7JJ3X82',
  2.          'secret_access_key' => 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o'));

The wrapper may be registered multiple times with different prefixes to allow access using different access keys.

Options may also be specified using a PHP stream context.

  • Access: public

Parameters:

string   $wrapper   —  the wrapper scheme, i.e. the string preceding "://" in paths like "s3://mybucket/mykey"
array   $options   —  associate array of key-value pairs

[ Top ]

rename   [line 579]

bool rename( string $fromPath, string $toPath)

Support for rename(). The renaming isn't atomic as rename() usually is, but the write part is.

Parameters:

string   $fromPath   —  the path to the file to rename
string   $toPath   —  the new path to the file

[ Top ]

rmdir   [line 675]

bool rmdir( string $path, int $options)

Support for rmdir().

Note: This method uses @ to suppress errors from unlink().


Parameters:

string   $path   —  the directory path
int   $options   —  a bit mask of STREAM_REPORT_ERRORS

[ Top ]

stream_close   [line 488]

void stream_close( )

Support for fclose().

[ Top ]

stream_eof   [line 405]

bool stream_eof( )

Support for feof().

[ Top ]

stream_flush   [line 437]

bool stream_flush( )

Support for fflush().

[ Top ]

stream_open   [line 298]

bool stream_open( string $path, string $mode, int $options, string &$opened_path)

Support for fopen(). Also used by file_get_contents() and file_put_contents().
  • Return: true on success
  • Access: public

Parameters:

string   $path   —  the path to open
string   $mode   —  the file mode ( "r", "wb" etc.)
int   $options   —  a bit mask of STREAM_USE_PATH and STREAM_REPORT_ERRORS
string   &$opened_path   —  the file actually opened

[ Top ]

stream_read   [line 375]

string|false stream_read( int $count)

Support for fread(), file_get_contents() etc.

Parameters:

int   $count   —  maximum number of bytes to be read

[ Top ]

stream_seek   [line 422]

bool stream_seek( int $offset, int $whence)

Support for fseek().

Parameters:

int   $offset   —  the byte offset to got to
int   $whence   —  SEEK_SET, SEEK_CUR, or SEEK_END

[ Top ]

stream_stat   [line 466]

array stream_stat( )

Support for fstat().

[ Top ]

stream_tell   [line 451]

int stream_tell( )

Support for ftell().

[ Top ]

stream_write   [line 391]

int stream_write( string $data)

Support for fwrite(), file_put_contents() etc.

Parameters:

string   $data   —  the data to be written

[ Top ]

unlink   [line 538]

bool unlink( string $path)

Support for unlink().

Parameters:

string   $path   —  the file path

[ Top ]

url_stat   [line 718]

array url_stat( string $path, int $flags)

Support for stat().

Parameters:

string   $path   —  the to get information about.
int   $flags   —  a bit mask of STREAM_URL_STAT_LINK and STREAM_URL_STAT_QUIET

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:49:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.