class DrupalPublicStreamWrapper

Drupal public (public://) stream wrapper class.

Provides support for storing publicly accessible files with the Drupal file interface.

Hierarchy

Expanded class hierarchy of DrupalPublicStreamWrapper

5 string references to 'DrupalPublicStreamWrapper'
hook_stream_wrappers in modules/system/system.api.php
Registers PHP stream wrapper implementations associated with a module.
StreamWrapperTest::testGetClassName in modules/simpletest/tests/file.test
Test the getClassName() function.
StreamWrapperTest::testGetInstanceByScheme in modules/simpletest/tests/file.test
Test the file_stream_wrapper_get_instance_by_scheme() function.
StreamWrapperTest::testUriFunctions in modules/simpletest/tests/file.test
Test the URI and target functions.
system_stream_wrappers in modules/system/system.module
Implements hook_stream_wrappers().

File

includes/stream_wrappers.inc, line 920

View source
class DrupalPublicStreamWrapper extends DrupalLocalStreamWrapper {
  
  /**
   * Implements abstract public function getDirectoryPath()
   */
  public function getDirectoryPath() {
    return variable_get('file_public_path', conf_path() . '/files');
  }
  
  /**
   * Overrides getExternalUrl().
   *
   * Return the HTML URI of a public file.
   */
  function getExternalUrl() {
    $path = str_replace('\\', '/', $this->getTarget());
    return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . drupal_encode_path($path);
  }
  
  /**
   * {@inheritdoc}
   */
  protected function getLocalPath($uri = NULL) {
    $path = parent::getLocalPath($uri);
    if (variable_get('sa_core_2022_012_override', FALSE)) {
      return $path;
    }
    $private_path = variable_get('file_private_path', FALSE);
    if ($private_path) {
      $private_path = realpath($private_path);
      if ($private_path && strpos($path, $private_path) === 0) {
        return FALSE;
      }
    }
    return $path;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.