PHP get the current path and directory example _php tutorial

Source: Internet
Author: User
The code is as follows


/**
* PHP Get path or directory implementation
* @link http://www.45it.com
*/

Magic variable to get the absolute path of the current file
echo "__file__: ========>". __file__;
Echo '
';

Magic variable, gets the directory of the current script
echo "__dir__: ========>". __dir__;
Echo '
';

DirName returns the directory portion of the path, DirName (__file__) is equivalent to __dir__
echo "DirName (__file__): ========>". dirname (__file__);
Echo '
';

The results of $_server[' php_self ' and $_server[' script_name '] are generally the same, they all get the file name of the current script
PHP is only a different way to run CGI, but now it's almost impossible to find a CGI run of PHP.
Echo ' $_server[' Php_self "]: ========> '. $_server[' php_self '];
Echo '
';

Echo ' $_server[' Script_name "]: ========> '. $_server[' Script_name '];
Echo '
';

The absolute path of the current execution script. Remember that running PHP in the CLI mode is not available
Echo ' $_server[' Script_filename "]: ========> '. $_server[' Script_filename '];
Echo '
';

The document root directory where the script is currently running. Defined in the server configuration file.
Echo ' $_server[' Document_root "]: ========> '. $_server[' Document_root '];
Echo '
';

GETCWD () returns the current working directory
echo "GETCWD (): ========>". GETCWD ();
Echo '
';

Echo '
';
echo "PHP tutorial (www.45it.com) collation";

(Note: $HTTP _server_vars and $_server are different variables, and PHP handles them in different ways.) If the register_globals directive is set, these variables are also available in all scripts, that is, the $_server and $HTTP _server_vars arrays are separated.

$_server[' Http_host '] gets the current request for HOST: header content

$_server[' php_self ' This is probably the most commonly used, it returns the file name of the page that is currently called, and if it is http://localhost/test/2005/test.php, it will return/test/2005/ test.php

$_server[' Script_name ') it will return the path containing the current script. This is useful when the page needs to point to itself

$_server[' Script_filename ') it returns the absolute path information where the current file is located

$_server[' Request_uri ' returns the URI required to access this page, including "/"

There are, of course, many path functions:

DirName (), returns the directory portion of the path information, preceded by a "/"

BaseName () returns the basic file name portion of the path and, of course, can also set the suffix to control the output.

Realpath (), returns the path of absolute normalization for path information

http://www.bkjia.com/PHPjc/741452.html www.bkjia.com true http://www.bkjia.com/PHPjc/741452.html techarticle the code is as follows? PHP/** * php Get path or directory implementation * @link http://www.45it.com *///Magic variable, get the absolute path of the current file echo __file__: ========. __file__; Echo ' BR ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.