function system_file_download

Same name in other branches
  1. 9 core/modules/system/system.module \system_file_download()
  2. 10 core/modules/system/system.module \system_file_download()
  3. 11.x core/modules/system/system.module \system_file_download()

Implements hook_file_download().

File

modules/system/system.module, line 4109

Code

function system_file_download($uri) {
    $scheme = file_uri_scheme($uri);
    if (file_stream_wrapper_valid_scheme($scheme)) {
        $target = file_uri_target($uri);
        if ($target !== FALSE) {
            if (!in_array($scheme, variable_get('file_sa_core_2023_005_schemes', array()))) {
                if (DIRECTORY_SEPARATOR !== '/') {
                    $class = file_stream_wrapper_get_class($scheme);
                    if (is_subclass_of($class, 'DrupalLocalStreamWrapper')) {
                        $target = str_replace(DIRECTORY_SEPARATOR, '/', $target);
                    }
                }
                $parts = explode('/', $target);
                if (array_intersect($parts, array(
                    '.',
                    '..',
                ))) {
                    return -1;
                }
            }
        }
    }
    $core_schemes = array(
        'public',
        'private',
        'temporary',
    );
    $additional_public_schemes = array_diff(variable_get('file_additional_public_schemes', array()), $core_schemes);
    if ($additional_public_schemes) {
        $scheme = file_uri_scheme($uri);
        if (in_array($scheme, $additional_public_schemes, TRUE)) {
            return array(
                // Returning any header grants access, and setting the 'Cache-Control'
                // header is appropriate for public files.
'Cache-Control' => 'public',
            );
        }
    }
}

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