TemporaryStream.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php
  2. 8.9.x core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php
  3. 10 core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php

Namespace

Drupal\Core\StreamWrapper

File

core/lib/Drupal/Core/StreamWrapper/TemporaryStream.php

View source
<?php

namespace Drupal\Core\StreamWrapper;

use Drupal\Core\Url;

/**
 * Defines a Drupal temporary (temporary://) stream wrapper class.
 *
 * Provides support for storing temporarily accessible files with the Drupal
 * file interface.
 */
class TemporaryStream extends LocalStream {
    
    /**
     * {@inheritdoc}
     */
    public static function getType() {
        return StreamWrapperInterface::LOCAL_HIDDEN;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getName() {
        return t('Temporary files');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDescription() {
        return t('Temporary local files for upload and previews.');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDirectoryPath() {
        return \Drupal::service('file_system')->getTempDirectory();
    }
    
    /**
     * {@inheritdoc}
     */
    public function getExternalUrl() {
        $path = str_replace('\\', '/', $this->getTarget());
        return Url::fromRoute('system.temporary', [], [
            'absolute' => TRUE,
            'query' => [
                'file' => $path,
            ],
        ])->toString();
    }

}

Classes

Title Deprecated Summary
TemporaryStream Defines a Drupal temporary (temporary://) stream wrapper class.

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