file_create_url

Definition

file_create_url($path)
includes/file.inc, line 30

Description

Create the download path to a file.

Parameters

$path Path to the file to generate URL for

Return value

URL pointing to the file

Related topics

Namesort iconDescription
File interfaceCommon file handling functions.

Code

<?php
function file_create_url($path) {
  if (strpos($path, variable_get('file_directory_path', 'files')) !== false) {
    $path = trim(substr($path, strlen(variable_get('file_directory_path', 'files'))), '\\/');
  }
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return $GLOBALS['base_url'] .'/'. variable_get('file_directory_path', 'files') .'/'. str_replace('\\', '/', $path);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files', 'file='. $path, NULL, TRUE);
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.