Results 1 to 4 of 4

Thread: How to find absolute path of a file on the server with the help of PHP function

  1. #1
    Join Date
    Aug 2008
    Posts
    129

    How to find absolute path of a file on the server with the help of PHP function

    Which method or function should I used to find the absolute path of a file on the server in PHP ?. I have tried out some function in my programming classes to find out the file server it works fine but now when I finding out which are those functions or methods I am unable to find it out. Please let me know which are those functions or any other way to handle the same problem.

  2. #2
    Join Date
    Oct 2008
    Posts
    117

    Re: How to find absolute path of a file on the server with the help of PHP function

    Following is the method where it will help to find the absolute path of a file on the server, you need to keep this file at the httdocs to run the same file.

    PHP Code:
    <?php
    $p 
    getcwd();
    echo 
    $p;
    ?>
    Ans: getcwd()

    Here I have stored my files under httdocs (using php5,i haven't checked under php4) so I get the output as C:\apache2triad\htdocs you may get your path information while runnings the above code.

  3. #3
    Join Date
    Feb 2006
    Posts
    172

    Re: How to find absolute path of a file on the server with the help of PHP function

    In PHP to keep the file at the root mode you need to use the function naming convention like this, echo $_SERVER['DOCUMENT_ROOT']; It return the file system path to your root directory by examining a server variable.

    You may also use the following method i.e echo getcwd(); This will return the file system path to the directory that run this command.

    echo $_SERVER['PHP_SELF']; It return the Absolute Path to the file.

  4. #4
    Join Date
    Mar 2008
    Posts
    192

    Re: How to find absolute path of a file on the server with the help of PHP function

    The absolute path of your local server and the real server might be different. So to get the absolute path for both version, you can take the help of the magic constant called __FILE__ and dirname() function available in PHP.

    The $_SERVER['PHP_SELF'] doesn't return that, it only return the URI part, e.G.

    If url = 'http://site.Com/abc/def.Php'

    $_SERVER['PHP_SELF'] returns '/abc/def.Php', this is definitely not absolute path
    (tested under PHP 4.X)

Similar Threads

  1. Better amongst the absolute or relative path in HTML
    By Galeny in forum Software Development
    Replies: 3
    Last Post: 23-12-2009, 10:54 PM
  2. Sandisk cruzer micro 2.0gb can not find path.
    By Shaan12 in forum Hardware Peripherals
    Replies: 3
    Last Post: 03-12-2009, 03:32 AM
  3. Absolute path to run JAR file
    By joel84 in forum Software Development
    Replies: 3
    Last Post: 30-04-2009, 02:05 PM
  4. Cannot find network path on my Vista machine
    By Azzan in forum Networking & Security
    Replies: 5
    Last Post: 04-04-2009, 09:01 PM
  5. How do I find 'Profile Path' details?
    By hariharan_00 in forum Active Directory
    Replies: 3
    Last Post: 08-05-2007, 07:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,563,003.47988 seconds with 17 queries