access root folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    access root folder

    is code are ok or not [PHP]$_SERVER['DOCUMENT_ROOT'].'armese_data/call/call.php'[/PHP] to access the root folder for security from downloading the files by direct url.
  • webster5u
    New Member
    • Jan 2008
    • 28

    #2
    if i not mistake, in Linux environment $_SERVER['DOCUMENT_ROOT'] will not append / at last character at default directory path.

    Comment

    • smartic
      New Member
      • May 2007
      • 150

      #3
      what is the alternative for this code to access the root folder?

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        The root folder of what?

        If you want to access the root directory of your Linux system, simply appending / to any path will jump to the root directory
        For example: "/var/www/html"

        If you want the web-root, meaning the top level directory accessible from your HTTP server, you could do:
        Code:
        $_SERVER['DOCUMENT_ROOT'] . "/path/to/file.ext"

        Comment

        • smartic
          New Member
          • May 2007
          • 150

          #5
          my point is how can i access files by php outside the public_html folder like files i want only registerd users only to access it or files i use it for my connection with DB ?

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            PHP can access any file on the server's file-system, granted that it has the proper permission.
            You can use absolute paths with most of PHP's file functions, such as include and readfile.

            Like, say, if you had a DB connection script stored in "/var/www/include", you could simply do:
            [code=php]
            include("/var/www/include/dbConnect.php") ;
            [/code]
            If your web-root is located at "/var/www/html", and the current script is at the web-root, you could also use a relative path, like:
            [code=php]
            include("../include/dbConnect.php") ;
            [/code]
            On Windows, using a path like "C:\\SomeDir\my file.php" should also be perfectly valid.

            Comment

            Working...