Heim > Backend-Entwicklung > PHP-Tutorial > php路径有关问题

php路径有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-13 10:56:31
Original
975 Leute haben es durchsucht

php路径问题
1、如果目录结构简单,可以通过调整包含文件的层次结构来解决,仍然使用相对路径。
3、结合使用绝对路径和相对路径,有时为了赶进度可以先行让项目通过。
4、使用dirname(__FILE__)获取当前文件的目录路径,比如:
require_once(dirname(__FILE__)."../../include/cfg.php");
5、使用下面的这个语句可以把当前目录设置为当前文件的目录路径,也较为方便,尤其是交叉引用的时候非常有用。
chdir(dirname(__FILE__));
6、对于使用虚拟主机的用户可以在包含文件之前使用set_include_path()函数,比如:
set_include_path(‘./’.PATH_SEPARATOR.dirname(__FILE__));
require_once(‘include/cfg.php’);
7、通过辅助设置php配置文件中的的include_path参数进行查询路径,include_path是指将要用到的包含文件所在的目录,可以将经常include文件放到一个统一的目录里,然后把这个目录设置在配置文件php.ini的include_path参数后面,在需要使用这些包含文件的时候只需要包含其名称即可,比如就可以了,而实际上metsky_cfg.php文件则是存在设置的文件目录里。
附PHP.ini文件中include_path部分内容:
;;;;;;;;;;;;;;;;;;;;;;;;;
; 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 was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are 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、通过.htaccess配置文件进行路径修改也可以达到上一条类似的效果,比如
php_value include_path "./include"


ref:http://www.metsky.com/archives/323.html

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage