1

this is kind of odd question, i can't figure out how to use relative path /which will not be interpreted as my drive in my current computer.

I'm trying to build a gallery manager for a web site. the path "/" normally points to my public folder when using it in my web site (using a front controller). so technically to display images in my public/images i use /images now this seems not to work as i'm trying to load all the pictures of a particular folder in my site. am working on drive D so / points to it, when using opendir.

Is there anything i'm not using properly? or there is a need of an absolute path ? which (the site admin is not necessarily supposed to know).

thanks for reading this.

black sensei
  • 6,528
  • 22
  • 109
  • 188

1 Answers1

3

Use the magic constant __FILE__. In your index.php, dirname(__FILE__) will get the path to main directory. Assign it to a constant and use it wherever you like.

Noumenon
  • 5,099
  • 4
  • 53
  • 73
Norbert Orzechowicz
  • 1,329
  • 9
  • 20
  • So in this i don't have any way of using relative path but rather absolute path using the root path that the constant you are referring to points to. am i getting it rignt? – black sensei Dec 03 '11 at 21:57
  • Yea, absolute path is more certain method. Many frameworks use this method to store APPLICATION_PATH for including files. – Norbert Orzechowicz Dec 03 '11 at 21:59
  • So it will be simple in Zend. Constant value APPLICATION_PATH points to application folder. So if you need access to public folder for example you can use echo APPLICATION_PATH . '/../public/'; – Norbert Orzechowicz Dec 03 '11 at 22:23