function file_directory_path

You are here

4.7 file.inc file_directory_path()
5 file.inc file_directory_path()
6 file.inc file_directory_path()

Determine the default 'files' directory.

Return value

A string containing the path to Drupal's 'files' directory.

Related topics

15 calls to file_directory_path()
color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.
drupal_get_css in includes/common.inc
Returns a themed representation of all stylesheets that should be attached to the page.
drupal_get_js in includes/common.inc
Returns a themed presentation of all JavaScript code for the current page.
file_check_directory in includes/file.inc
Checks whether a directory exists and is writable.
file_create_path in includes/file.inc
Make sure the destination is a complete path and resides in the file system directory, if it is not prepend the file system directory.

... See full list

3 string references to 'file_directory_path'
system_file_system_settings in modules/system/system.admin.inc
Form builder; Configure the site file handling.
system_theme_settings in modules/system/system.admin.inc
Form builder; display theme configuration for entire site and individual themes.
system_update_6046 in modules/system/system.install
Ensure that the file_directory_path variable is set (using the old 5.x default, if necessary), so that the changed 6.x default won't break existing sites.

File

includes/file.inc, line 1102
API for handling file uploads and server file management.

Code

function file_directory_path() {
  return variable_get('file_directory_path', conf_path() . '/files');
}

Comments

file_directory_path has been removed in 7.x.

Instead, use:

<?php
file_default_scheme
() . ':/'
?>

see http://drupal.org/update/modules/6/7#file_directory_path

You can try this:

drupal_realpath('public://')

Well, file_default_scheme() seems to be more sensible, as it returns 'public' or 'private' according to the value set in file_default_scheme variable.

If you want the relative path in D7 (same as file_directory_path() in D6) use:
variable_get('file_' . file_default_scheme() . '_path', conf_path() . '/files');

If you want the absolute path in D7 use:
drupal_realpath(file_default_scheme() . '://');

In D6, file_directory_path() returns the relative path.

Wonderful!

Thanks-- I wish D7 had left in file_directory_path(), and just marked it as "deprecated" or some such.

This returns the path relative to the Drupal root folder, eg 'sites/default/files'.

You mean that file_directory_path returned that in D6? No one has posted a way to do the same thing!

<?php
  variable_get
('file_public_path', conf_path() . '/files')
?>

This gives you exactly the same as file_directory_path() in D6.

The full filesystem path to the files folder:
$_SERVER['DOCUMENT_ROOT'] . base_path() . file_directory_path()

FYI: This breaks for private filesystems.

The best I've sorted is something like this:

<?php
if(variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE){
 
$path = file_directory_path();
} else {
 
$path = $_SERVER['DOCUMENT_ROOT'] . base_path() . file_directory_path();
}
?>

function file_realpath($uri) {
  $scheme = file_uri_scheme($uri);
  $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
  return $_SERVER['DOCUMENT_ROOT'] . '/' . $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
}