PHP Path-related issues

Source: Internet
Author: User
PHP path problem
1, if the directory structure is simple, you can adjust the include file hierarchy to resolve, still use relative path.
3, combined with the absolute path and relative path, sometimes in order to catch up with the progress of the project to pass.
4, use DirName (__file__) to get the directory path of the current file, such as:
Require_once (DirName (__file__).. /.. /include/cfg.php ");
5, using the following statement can be used to set the current directory is the directory path of the current file, but also more convenient, especially when cross-referencing is very useful.
ChDir (DirName (__file__));
6. For users who use a virtual host, they can use the Set_include_path () function before the include file, for example:
Set_include_path ('./'. Path_separator.dirname (__file__));
Require_once (' include/cfg.php ');
7, through the auxiliary set PHP configuration file in the include_path parameter query path, include_path refers to the containing file will be used in the directory, you can put the regular include files in a unified directory, This directory is then set to the Include_path parameter of the configuration file php.ini, which needs to include its name when it is necessary to use the included files, such as Yes, and actually the metsky_cfg.php file is in the file directory where the settings exist.
Attached to the php.ini file include_path part of the content:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and directories;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
; include_path = ".:/ Php/includes "
;
; Windows: "Path1;path2"
; include_path = ".; C:phpincludes "
;
; PHP ' s default setting for Include_path is ".; Path/to/php/pear "
; Http://php.net/include-path
include_path = ".;D: \ Xampp\php\pear "

; The root of the PHP pages, used only if nonempty.
; If PHP is not compiled with Force_redirect, you should set Doc_root
; If you is running PHP as a CGI under any Web server (other than IIS)
; See documentation for security issues. The alternate is to use the
; Cgi.force_redirect Configuration Below
; Http://php.net/doc-root
Doc_root =

; The directory under which PHP opens the script using/~username used only
; If nonempty.
; Http://php.net/user-dir
User_dir =

; Directory in which the loadable Extensions (modules) reside.
; Http://php.net/extension-dir
; Extension_dir = "./"
; On Windows:
; Extension_dir = "ext"
Extension_dir = "D:\xampp\php\ext"

......
8, through the. htaccess configuration file for path modification can also achieve a similar effect, such as
Php_value include_path "./include"


Ref:http://www.metsky.com/archives/323.html
  • 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.