Ok first let me start off by saying there are folders, here is the architecture:

..
[]admin
->[]includes
[]images
application.php

Ok here is my question. In application.php there is a universal class that is used by everything on the website to display images, template files, etc. But it won't work for some files because they are in different folders. A file in the includes folder wouldn't be able to access the images folder if the class was designed for a file in the admin folder. So i am wondering, is there a function or command that allows the path to always start from the index instead of where the respective file is located? I have tried $_SERVER['DOCUMENT_ROOT'] but that gives the absolute root and doesn't work. Thank you for your time!

    let's say you can modify your php.ini:

    ; UNIX: "/path1:/path2"

    ;include_path = ".:/php/includes"
    ;
    ; Windows: "\path1;\path2"
    ;include_path = ".;c:\php\includes"

    php.net/include


    now let's say you can't
    you may have to change your code.. setup a config var, like
    $CFGroot = '/where/am/i/absolute/';
    so you can include files like this
    include($CFGroot.'file.php');

    sure you cant use relative paths? your structure needs to change?
    hope that helps, see what is better for you.

      THanks for responding. Well I have this class:

      class Config extends Db
      	{
      		var $wwwRoot;
      		var $dirRoot;
      		var $includesRoot;
      		var $imagesRoot;
      
      	// assigns config info
      	function config()
      		{
      			$this->wwwRoot      = "."; 
          		$this->dirRoot      = "/home/user_name/public_html"; 
          		$this->includesRoot = $this->wwwRoot . "/includes"; 
         			$this->imagesRoot   = $this->wwwRoot . "/images";
      	}
      }
      

      and those are used in another class, called Page which all the pages use, but the pages are each in different folders. So all the paths will be different to an images folder

        when you say

        $this->wwwRoot = ".";

        it means that your root is on same folder where this class is. variables for image folder and includes folder uses that wwwroot var.

        try to put an absolute path on this, like

        $this->wwwRoot = "/home/username/www/startsitefolder";

        or move your class to this folder - in this case, dont change anything on code.

          the absolute root doesnt work, cause it makes the link look like

          htt[p://www.domain.com/home/user/public_html/images/

          and i dont want to copy each and every class file which would defeat the purpose of having one

            so you dont need an absolute server link but an absolute webserver link..
            is your images folder on webserver root?
            in other words, is your images acessible by www.url.com/images/imagename.gif ?
            so, your root is just '/'

              i cannot think in nothing better than:

                      function config() { 
                              $this->wwwRoot  = "";  // may be '/' too
                              $this->dirRoot      = "/home/user_name/public_html";
                              $this->includesRoot = $this->dirRoot . "/includes";  
              $this->imagesRoot = $this->wwwRoot . "/images"; }

              note i changed includesRoot to use dirRoot var and not wwwRoot.. for me it makes more sense.
              and for images, i am assuming your images folder is on www.url.com/images/

              thats all

                Write a Reply...