Search code examples
phprelative-pathimage-galleryopendir

How to get opendir point to my public folder with the relative path "/"


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.


Solution

  • 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.