php中的路径问题与set_include_path使用介绍

Stephenie ·
更新时间:2024-09-21
· 507 次阅读

first:
php中常用的路径
当前文件路径:D:\phpweb\php_example\include_path.php
代码如下:
1.dirname(__FILE__); //输出D:\phpweb\php_example
2.$_SERVER['SCRIPT_FILENAME']; //输出D:/phpweb/php_example/include_path.php

second:
php中的set_include_path
在php中,include文件时,当包含路径不为相对也不为绝对时(如:include("example.php")),会先查找include_path所设置的目录,然后再在当前目录查找,这也是为什么很多资料上提到include("./example.php")比include("example.php")效率高的原因。
方法:
1.ini_set("include_path", "/usr/lib/pear"); //所有版本
2.set_include_path("/usr/lib/pear"); //version>=4.3.0
可以用下面的方法,在原有目录上添加目录
代码如下:
<?php
$path = '/usr/lib/pear';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);//设置后的include_path变为类似/usr/lib/function;/usr/lib/pear
?>
您可能感兴趣的文章:PHP中set_include_path()函数相关用法分析php mysql like 实现多关键词搜索的方法php通过PHPExcel导入Excel表格到MySQL数据库的简单实例遍历指定目录,并存储目录内所有文件属性信息的php代码PHP图像识别技术原理与实现PHP下的浮点运算不准的解决方法PHP读取大文件的几种方法介绍php set_include_path函数设置 include_path 配置选项



path set PHP include

需要 登录 后方可回复, 如果你还没有账号请 注册新账号