Saturday, October 29, 2011

get absolute path in drupal modules

The following codes is in /var/www/drupal-6.22/sites/all/modules/mymodule/mymodule.module

  echo dirname(__FILE__)
  = /var/www/drupal-6.22/sites/all/modules/mymodule

  echo realpath(".");
  = /var/www/drupal-6.22

  echo realpath(drupal_get_path('module', 'mymodule'));
  = /var/www/drupal-6.22/sites/all/modules/mymodule

  echo $_SERVER['DOCUMENT_ROOT'] . base_path();
  = /var/www//drupal-6.22/

  global $base_url;
  echo $base_url;
  = http://bmms:8080/drupal-6.22

  echo base_path(); // drupal function
  = /drupal-6.22/

  $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'filename.ext';
  $data = file( $path );
  foreach($data as $value) {
    $output .= "$value";
  }


http://php.net/manual/en/language.constants.predefined.php
http://php.net/manual/en/function.dirname.php
http://php.net/manual/en/function.realpath.php

No comments:

Post a Comment