Several functions in PHP for obtaining paths

by bookmarkscjl on 2008-08-25 15:37:57

Here is the translation of your text into English, including the explanation of the PHP code:

---

Several functions in PHP for obtaining file paths:

Code as follows:

```php

"; // Get the server document root

echo $_SERVER['PHP_SELF'].""; // Get the absolute server path of the file executing this code

echo __FILE__.""; // Get the absolute file system path of the file

echo dirname(__FILE__); // Get the directory path where the file resides

?>

```

### Explanation of the Code:

1. **`$_SERVER['DOCUMENT_ROOT']`**: Retrieves the root directory of the server's document (the web root).

2. **`$_SERVER['PHP_SELF']`**: Retrieves the absolute server path of the file that is currently executing this code.

3. **`__FILE__`**: Retrieves the absolute file system path of the current file.

4. **`dirname(__FILE__)`**: Retrieves the directory path where the current file resides.

Let me know if you need further clarification!