Hi,

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?

<?php
$path_base_dir = '/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

Comments

kitt’s picture

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.

chrisrikli’s picture

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

xtfer’s picture

And i was the third. Good work!

anztenney’s picture

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

Mark Theunissen’s picture

The Drupal functions below will help:


print file_directory_path();
print base_path();

http://api.drupal.org/api/function/file_directory_path/5
http://api.drupal.org/api/function/base_path/5
__________________________________________________________

Mark Theunissen

Code Baboon
Drupal based services

Swift Arrow’s picture

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.

dan.mantyla’s picture

file_directory_path() has been removed, so use this method now:

echo file_create_url(file_default_scheme()."://");

example:

<img src="<?php echo file_create_url(file_default_scheme()."://"); ?>/my-image.png" />