Is there a way to determine the server filesystem path to the drupal install directory? I am writing a module that reads the fienames of all images in a subdirectory in 'files' (i.e., the value of the file_directory_path system variable) and formats HTML for displaying the images -- a very simple image gallery generator that allows you to upload a bunch of images via FTP. However, I can't figure out how to get the filesystem path to the files directory. Is there a way to programmatically generate this? Or do I have to have the user set it in the module settings?

= '/path/to/my/files/directory/'; // <- This is what I want to determine programatically -- or do I have to store it in variables table using variable_set and variable_get?
$data_dir = 'my_data_dir/';
$path_data_dir = $path_base_dir . $data_dir;
$files = file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0, $recurse = TRUE, $key = 'filename', $min_depth = 0, $depth = 0);
foreach (
$files as $file) {
$file->name . '</p>';

TIA, Mark


Your file system path should be $_SERVER['DOCUMENT_ROOT'] . base_path();

However, in your example, this path isn't needed. file_scan_directory() starts at the top of the document root and searches below that.

An example:

If you have the files in your default "files" directory named "a.css" "b.css" and "c.css", then this snippet:

$a = file_scan_directory('files', 'css');

will get you a listing of a.css, b.css and c.css

BTW, if you're asking, "why respond a question over a year old," my answer would be, "because this page is the first listing for the google query for 'drupal determining system file path'." Best to have an answer for the next person looking.

...and I was that next person. Thanks kitt

And i was the third. Good work!


$_SERVER['DOCUMENT_ROOT'] . base_path().file_directory_path()

The Drupal functions below will help:

print file_directory_path();


Mark Theunissen

Code Baboon
Drupal based services

file_directory_path() is what I was looking for. I needed to define some theme functions to look in the files directory of the site, not in the theme directory.

My first professional Drupal Site: http://www.WiseEarthPublishers.com. Also happens to be my own company! :)
Running a programming challenge with €1000 prize! http://www.WiseEarthTechnology.com