Class StreamWrapper
Amazon S3 stream wrapper to use "s3://
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
Methods Summary
-
static
register ( Aws\S3\S3ClientInterface $client, string $protocol = 's3', Aws\CacheInterface $cache = null, $v2Existence = false )
Register the 's3://' stream wrapper
- stream_close ( )
- stream_open ( $path, $mode, $options, & $opened_path )
- stream_eof ( )
- stream_flush ( )
- stream_read ( $count )
- stream_seek ( $offset, $whence = SEEK_SET )
- stream_tell ( )
- stream_write ( $data )
- unlink ( $path )
- stream_stat ( )
-
url_stat ( $path, $flags )
Provides information for is_dir, is_file, filesize, etc. Works on buckets, keys, and prefixes.
-
mkdir ( string $path, int $mode, int $options )
Support for mkdir().
- rmdir ( $path, $options )
-
dir_opendir ( string $path, string $options )
Support for opendir().
-
dir_closedir ( )
Close the directory listing handles
-
dir_rewinddir ( )
This method is called in response to rewinddir()
-
dir_readdir ( )
This method is called in response to readdir()
-
rename ( string $path_from, string $path_to )
Called in response to rename() to rename a file or directory. Currently only supports renaming objects.
- stream_cast ( $cast_as )
Methods Details
static
register (
Aws\S3\S3ClientInterface
$client,
string
$protocol = 's3',
Aws\CacheInterface
$cache = null,
$v2Existence = false
)
Register the 's3://' stream wrapper
Parameters
Aws\S3\S3ClientInterface |
$client | Client to use with the stream wrapper |
string | $protocol = 's3' | Protocol to register as. |
Aws\CacheInterface |
$cache = null | Default cache for the protocol. |
$v2Existence = false |
stream_close ( )
stream_open ( $path, $mode, $options, & $opened_path )
stream_eof ( )
stream_flush ( )
stream_read ( $count )
stream_seek ( $offset, $whence = SEEK_SET )
stream_tell ( )
stream_write ( $data )
unlink ( $path )
stream_stat ( )
url_stat ( $path, $flags )
Provides information for is_dir, is_file, filesize, etc. Works on buckets, keys, and prefixes.
Link
boolean mkdir ( string $path, integer $mode, integer $options )
Support for mkdir().
Parameters
string | $path | Directory which should be created. |
integer | $mode | 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. |
integer | $options | A bitwise mask of values, such as STREAM_MKDIR_RECURSIVE. |
Returns
boolean |
Link
rmdir ( $path, $options )
boolean dir_opendir ( string $path, string $options )
Support for opendir().
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
string | $path | The path to the directory (e.g. "s3://dir[]") |
string | $options | Unused option variable |
Returns
boolean true on success |
See
boolean dir_closedir ( )
Close the directory listing handles
Returns
boolean true on success |
boolean dir_rewinddir ( )
This method is called in response to rewinddir()
Returns
boolean true on success |
string dir_readdir ( )
This method is called in response to readdir()
Returns
string Should return a string representing the next filename, or false if there is no next file. |
Link
boolean rename ( string $path_from, string $path_to )
Called in response to rename() to rename a file or directory. Currently only supports renaming objects.
Parameters
string | $path_from | the path to the file to rename |
string | $path_to | the new path to the file |
Returns
boolean true if file was successfully renamed |