file_create_url

Versions
4.6 – 6
file_create_url($path)
7
file_create_url($uri)

Create the download path to a file.

Parameters

$path A string containing the path of the file to generate URL for.

Return value

A string containing a URL that can be used to download the file.

Related topics

▾ 6 functions call file_create_url()

blogapi_metaweblog_new_media_object in modules/blogapi.module
Blogging API callback. Inserts a file into Drupal.
fileupload_view in developer/examples/fileupload.module
Implementation of hook_view.
theme_upload_attachments in modules/upload.module
Displays file attachments in table
theme_user_picture in modules/user.module
upload_nodeapi in modules/upload.module
Implementation of hook_nodeapi().
_upload_form in modules/upload.module

Code

includes/file.inc, line 28

<?php
function file_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())), '\\/');
  }
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
    case FILE_DOWNLOADS_PUBLIC:
      return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
    case FILE_DOWNLOADS_PRIVATE:
      return url('system/files/'. $path, NULL, NULL, TRUE);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.