You are here

function _stage_file_proxy_get_current_file_uri in Stage File Proxy 7

Fetches a normalized file URI from the current request.

Parameters

string $path.: An optional path

Return value

bool|string A string containing the file URI, or FALSE if the current request is not for a public file.

1 call to _stage_file_proxy_get_current_file_uri()
stage_file_proxy_init in ./stage_file_proxy.module
Implements hook_init().

File

./stage_file_proxy.module, line 237
Stage File Proxy Module.

Code

function _stage_file_proxy_get_current_file_uri($path = NULL) {
  if (!isset($path)) {
    $path = $_GET['q'];
  }

  // Disallow directory traversal.
  if (in_array('..', explode('/', $path))) {
    return FALSE;
  }

  // Make sure we're requesting a file in the files dir.
  // Currently this only works for PUBLIC files.
  $file_dir = _stage_file_proxy_file_dir();
  if (strpos($path, $file_dir) !== 0) {
    return FALSE;
  }
  $uri = 'public://' . ltrim(drupal_substr($path, drupal_strlen($file_dir)), '/');
  return $uri;
}