I use PHP 4.3.10 opendir() function to open directory from a given path...

I want to use the relative path:

$path = "/images/contents";

...

@opendir($path);

But it says the path is not accessible...

But when I use:

$path = $_SERVER[DOCUMENT_ROOT]."/images/contents";

it works fine...

Why am I not able to use a relative path???

The dir structure is:

root
->images
-->contents
...

Help!

Thanks.

    here remove the first "/"

    $path = "images/contents";

      if you echo out the $_SERVER['DOCUMENT_ROOT'] you will see its something like /home/username/public_html depending on the setup. php is able to access anything on the server so its paths begin from the root drive (think of it like C:\ on windows) and the webserver has a base path (which is your document root) so html code uses this document root, where php uses the server root

        The script which is executing the opendir() is located in:

        root->admin->test->browser->browser.php

          echo $_SERVER['DOCUMENT_ROOT'];

          gives me:

          D:\Milan\Posao\DRI\Website

          which is actually the position of the root...

          How can I use the URL path instead of this directory path?

            keep using $_SERVER['DOCUMENT_ROOT']. thats the only way, or dont use a / in front

              Well, currently I'm building a website and testing it locally... Within the website, I'm building an image gallery browser with preview and upload fuinctions.

              If I use $_SERVER[DOCUMENT_ROOT], the image link includes:

              "D:/Milan/Posao/DRI/Website" and the browser complains:

              "D: is not a valid protocol..."

                Filepaths starting with '/' are absolute, not relative.
                Filepaths and URL paths are not the same thing.

                  OK,

                  does the ABSOLUTE PATH "/..." mean that it is relative to site root or what???

                  Why can't I use "/images" instead of "$_SERVER[DOCUMENT_ROOT]."images""???

                    /images refers to
                    D:/images <- doesnt exist

                    $_SERVER['DOCUMENT_ROOT]' . "/images" refers to
                    D:/Milan/Posao/DRI/Website/images <- correct

                    this is only what you use in php. for html you do use /images

                      Write a Reply...