SDK for PHP 3.x

StreamWrapper
in package

Amazon S3 stream wrapper to use "s3://<bucket>/<key>" files with PHP streams, supporting "r", "w", "a", "x".

Opening "r" (read only) streams:

Read only streams are truly streaming by default and will not allow you to seek. This is because data read from the stream is not kept in memory or on the local filesystem. You can force a "r" stream to be seekable by setting the "seekable" stream context option true. This will allow true streaming of data from Amazon S3, but will maintain a buffer of previously read bytes in a 'php://temp' stream to allow seeking to previously read bytes from the stream.

You may pass any GetObject parameters as 's3' stream context options. These options will affect how the data is downloaded from Amazon S3.

Opening "w" and "x" (write only) streams:

Because Amazon S3 requires a Content-Length header, write only streams will maintain a 'php://temp' stream to buffer data written to the stream until the stream is flushed (usually by closing the stream with fclose).

You may pass any PutObject parameters as 's3' stream context options. These options will affect how the data is uploaded to Amazon S3.

When opening an "x" stream, the file must exist on Amazon S3 for the stream to open successfully.

Opening "a" (write only append) streams:

Similar to "w" streams, opening append streams requires that the data be buffered in a "php://temp" stream. Append streams will attempt to download the contents of an object in Amazon S3, seek to the end of the object, then allow you to append to the contents of the object. The data will then be uploaded using a PutObject operation when the stream is flushed (usually with fclose).

You may pass any GetObject and/or PutObject parameters as 's3' stream context options. These options will affect how the data is downloaded and uploaded from Amazon S3.

Stream context options:

  • "seekable": Set to true to create a seekable "r" (read only) stream by using a php://temp stream buffer
  • For "unlink" only: Any option that can be passed to the DeleteObject operation

Table of Contents

Properties

$context  : resource|null

Methods

dir_closedir()  : bool
Close the directory listing handles
dir_opendir()  : bool
Support for opendir().
dir_readdir()  : string
This method is called in response to readdir()
dir_rewinddir()  : bool
This method is called in response to rewinddir()
mkdir()  : bool
Support for mkdir().
register()  : mixed
Register the 's3://' stream wrapper
rename()  : bool
Called in response to rename() to rename a file or directory. Currently only supports renaming objects.
rmdir()  : mixed
stream_cast()  : mixed
stream_close()  : mixed
stream_eof()  : mixed
stream_flush()  : mixed
stream_open()  : mixed
stream_read()  : mixed
stream_seek()  : mixed
stream_stat()  : mixed
stream_tell()  : mixed
stream_write()  : mixed
unlink()  : mixed
url_stat()  : mixed
Provides information for is_dir, is_file, filesize, etc. Works on buckets, keys, and prefixes.

Properties

$context

public resource|null $context

Stream context (this is set by PHP)

Methods

dir_closedir()

Close the directory listing handles

public dir_closedir() : bool
Return values
bool

true on success

dir_opendir()

Support for opendir().

public dir_opendir(string $path, string $options) : bool

The opendir() method of the Amazon S3 stream wrapper supports a stream context option of "listFilter". listFilter must be a callable that accepts an associative array of object data and returns true if the object should be yielded when iterating the keys in a bucket.

Parameters
$path : string

The path to the directory (e.g. "s3://dir[]")

$options : string

Unused option variable

Tags
see
http://www.php.net/manual/en/function.opendir.php
Return values
bool

true on success

dir_readdir()

This method is called in response to readdir()

public dir_readdir() : string
Tags
link
http://www.php.net/manual/en/function.readdir.php
Return values
string

Should return a string representing the next filename, or false if there is no next file.

dir_rewinddir()

This method is called in response to rewinddir()

public dir_rewinddir() : bool
Return values
bool

true on success

mkdir()

Support for mkdir().

public mkdir(string $path, int $mode, int $options) : bool
Parameters
$path : string

Directory which should be created.

$mode : int

Permissions. 700-range permissions map to ACL_PUBLIC. 600-range permissions map to ACL_AUTH_READ. All other permissions map to ACL_PRIVATE. Expects octal form.

$options : int

A bitwise mask of values, such as STREAM_MKDIR_RECURSIVE.

Tags
link
http://www.php.net/manual/en/streamwrapper.mkdir.php
Return values
bool

register()

Register the 's3://' stream wrapper

public static register(S3ClientInterface $client[, string $protocol = 's3' ][, CacheInterface $cache = null ][, mixed $v2Existence = false ]) : mixed
Parameters
$client : S3ClientInterface

Client to use with the stream wrapper

$protocol : string = 's3'

Protocol to register as.

$cache : CacheInterface = null

Default cache for the protocol.

$v2Existence : mixed = false

rename()

Called in response to rename() to rename a file or directory. Currently only supports renaming objects.

public rename(string $path_from, string $path_to) : bool
Parameters
$path_from : string

the path to the file to rename

$path_to : string

the new path to the file

Tags
link
http://www.php.net/manual/en/function.rename.php
Return values
bool

true if file was successfully renamed

rmdir()

public rmdir(mixed $path, mixed $options) : mixed
Parameters
$path : mixed
$options : mixed

stream_cast()

public stream_cast(mixed $cast_as) : mixed
Parameters
$cast_as : mixed

stream_close()

public stream_close() : mixed

stream_eof()

public stream_eof() : mixed

stream_flush()

public stream_flush() : mixed

stream_open()

public stream_open(mixed $path, mixed $mode, mixed $options, mixed &$opened_path) : mixed
Parameters
$path : mixed
$mode : mixed
$options : mixed
$opened_path : mixed

stream_read()

public stream_read(mixed $count) : mixed
Parameters
$count : mixed

stream_seek()

public stream_seek(mixed $offset[, mixed $whence = SEEK_SET ]) : mixed
Parameters
$offset : mixed
$whence : mixed = SEEK_SET

stream_stat()

public stream_stat() : mixed

stream_tell()

public stream_tell() : mixed

stream_write()

public stream_write(mixed $data) : mixed
Parameters
$data : mixed
public unlink(mixed $path) : mixed
Parameters
$path : mixed
On this page