Community Documentation

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

▾ 14 functions call 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.
file_create_url in includes/file.inc
Create the download path to a file.
file_directory_temp in includes/file.inc
Determine the default temporary directory.
system_file_system_settings in modules/system/system.admin.inc
Form builder; Configure the site file handling.
system_performance_settings in modules/system/system.admin.inc
Form builder; Configure site performance settings.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
system_theme_settings in modules/system/system.admin.inc
Form builder; display theme configuration for entire site and individual themes.
upload_form_alter in modules/upload/upload.module
upload_node_form_submit in modules/upload/upload.module
Save new uploads and store them in the session to be associated to the node on upload_save.
user_admin_settings in modules/user/user.admin.inc
Form builder; Configure user settings for this site.

File

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

Code

<?php
function file_directory_path() {
  return variable_get('file_directory_path', conf_path() . '/files');
}
?>

Comments

removed in 7.x

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

Drupal 7 way

You can try this:

drupal_realpath('public://')

More sensible

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.

Re: More sensible

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

Wonderful!

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

This returns the path

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

You mean that

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

<?php 

<?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 full filesystem path to the files folder:
$_SERVER['DOCUMENT_ROOT'] . base_path() . file_directory_path()

FYI: This breaks for private

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();
}
?>

This works for both public and private files given a URI

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);
}

Login or register to post comments