1 file_example_session_streams.inc public FileExampleSessionStreamWrapper::stream_open($uri, $mode, $options, &$opened_path)

Opens a stream, as for fopen(), file_get_contents(), file_put_contents().

Parameters

string $uri: A string containing the URI to the file 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: A string containing the path actually opened.

Return value

bool: Returns TRUE if file was opened successfully. (Always returns TRUE).

Overrides StreamWrapperInterface::stream_open

See also

http://php.net/manual/en/streamwrapper.stream-open.php

File

modules/examples/file_example/file_example_session_streams.inc, line 228
Provides a demonstration session:// streamwrapper.

Class

FileExampleSessionStreamWrapper
Example stream wrapper class to handle session:// streams.

Code

public function stream_open($uri, $mode, $options, &$opened_path) {
  $this->uri = $uri;
  // We make $session_content a reference to the appropriate key in the
  // $_SESSION variable. So if the local path were
  // /example/test.txt it $session_content would now be a
  // reference to $_SESSION['file_example']['example']['test.txt'].
  $this->sessionContent = &$this->uri_to_session_key($uri);

  // Reset the stream pointer since this is an open.
  $this->streamPointer = 0;
  return TRUE;
}