You are here

function swftools_create_url in SWF Tools 6.3

Creates a relative path url from a file path, using private or public file system.

This is an SWF Tools version of file_create_url(). The only difference is that here we do not output absolute paths as we are only using these paths within the context of a page and therefore relative is fine.

Parameters

string $path: Path to the file.

Return value

string A string with a complete path, relative to the local file system.

1 call to swftools_create_url()
swftools_get_url_and_path in ./swftools.module
Determines the url for a file, and expands its filepath if necessary.

File

./swftools.module, line 1472
The primary component of SWF Tools that enables comprehensive media handling.

Code

function swftools_create_url($path) {

  // Strip file_directory_path from $path. We only include relative paths in urls.
  if (strpos($path, file_directory_path() . '/') === 0) {
    $path = trim(substr($path, strlen(file_directory_path())), '\\/');
  }

  // Output a relative url, using public or private file transfer
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return base_path() . file_directory_path() . '/' . str_replace('\\', '/', $path);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/' . $path);
  }
}